【发布时间】:2017-02-07 04:24:05
【问题描述】:
我正在尝试在 typescript 项目中使用 sinon,并尝试使用其沙盒功能。我已经在建议的庄园中完成了我的测试,并且我正在尝试按照文档调用this.stub(/<em>stuff</em>/)。
不幸的是,当我这样做时,我收到以下错误TypeError: this.stub is not a function。作为测试,我在存根之前将this 打印到控制台,它是一个空对象。
以下是我尝试编写的测试失败的示例。非常感谢任何有关需要进行更改以使沙盒功能正常工作的建议。
import * as sinon from 'sinon'
import * as fs from 'fs'
describe("test",()=>
it("raise error notification if location does not exist", sinon.test(()=>{
this.stub(fs,"existsSync",(location: string)=> false)
/* rest of test */
}))
})
不使用沙盒功能并手动恢复存根确实可以参考。如果可能,尽量限制测试中的手动清理。
【问题讨论】:
-
share sinon import line else call like
import * as sinon from 'sinon'; -
@Venkatraman 我更新了代码以包含我的两个包含语句以及描述块。
标签: typescript sinon