试图解决测试内码的承诺

时间:2017-10-06 11:22:04

标签: javascript unit-testing promise

这是我的代码片段:

let that = this;
console.log('is logged');
this.$translate.onReady().then(() => {
  console.log('is ready - never logged');
  that.$translate.refresh().then(() => console.log('DONE - never logged'));
});

在我的测试中,我尝试调用this.$translate.onReady()以便记录console.log('is ready - never logged');。反过来调用refresh()

我怎样才能做到这一点?

spyOn($translate, 'onReady').and.returnValue(
{
  then:function() {
    console.log('is logged');
  }
});

0 个答案:

没有答案