【发布时间】:2019-04-20 09:09:16
【问题描述】:
我有一个间谍用于套件中多个测试的多个断言中。
如何清除或重置间谍,以便在每次测试中都认为间谍拦截的方法未被调用?
例如,如何使'does not run method'中的断言为真?
const methods = {
run: () => {}
}
const spy = jest.spyOn(methods, 'run')
describe('spy', () => {
it('runs method', () => {
methods.run()
expect(spy).toHaveBeenCalled() //=> true
})
it('does not run method', () => {
// how to make this true?
expect(spy).not.toHaveBeenCalled() //=> false
})
})
【问题讨论】:
标签: javascript testing jestjs