嘲弄名为进口和建造者的ES6& AVA

时间:2017-09-14 10:29:58

标签: javascript unit-testing ecmascript-6 ava

我有一个类构造函数,有一个我想要存根的函数:

class Service {
  constructor(){}
  async someFunction() {
    try {
    // does stuff
    }
    catch (e) {}
  }
}

在我要测试的文件中,这是导入的,如下所示:

const { Service } = require('something')
const newService = new Service('xyz')

我正努力让这个导入&在我的测试中正确存根。

目前正在进行如下导入:

t.context.service = {
  Service: class Service {
    constructor () {
      this.someFunction = sinon.stub()
    }
  }
}

这个导入似乎有效,但是我无法通过构建的版本获得对它的引用。对此有何帮助?

我希望能够做出如下的断言:

t.true(t.context.service.Service.someFunction.calledOnce)

1 个答案:

答案 0 :(得分:0)

AVA不提供任何存根。请查看https://github.com/testdouble/testdouble.js/http://sinonjs.org/

相关问题