类型错误:“未定义”是不是(评估'sinon.spy()')函数 [英] TypeError: 'undefined' is not a function (evaluating 'sinon.spy()')
问题描述
我试图使用 sinon.js 中的骨干应用的测试。但不幸的是,我不能用狙方法,由于错误:
I'm trying to use sinon.js in testing of a backbone application. But unfortunately I cannot use spy method due to error:
TypeError: 'undefined' is not a function (evaluating 'sinon.spy()')
下面是重现该错误的步骤:
Here is the steps to reproduce the error:
- 创建与骨干自耕农发电机 空项目
- 安装兴农:
CD测试&放大器;&安培;亭子安装兴农
- 在测试包含/ index.html的
< SCRIPT SRC =bower_components /兴农/ lib目录/ sinon.js>< / SCRIPT>
-
创建测试/规格/ test.js间谍:
- Create an empty project with backbone yeoman generator
- Install sinon:
cd test && bower install sinon
- Include in test/index.html
<script src="bower_components/sinon/lib/sinon.js"></script>
Create spy in test/spec/test.js:
describe('Give it some context', function () {
describe('maybe a bit more context here', function () {
it('should run here few assertions', function () {
var spy = sinon.spy();
spy.should.be.ok;
});
});
});
与运行繁重的测试:咕噜测试
测试将失败,并描述的错误。
The test will fail with a described error.
任何人都可以帮助找出什么是错的?
Could anyone help to find out what is wrong?
推荐答案
原来是间谍,存根等这样的功能,应通过包括的lib /兴农脚本手动添加
文件夹中。这一事实在安装部分提及。而且由于只在Node.js的环境核心sinon.js文件code这是自动完成的。
It turned out that such functionality as spies, stubs, etc should be added manually by including scripts from lib/sinon
folder. This fact is mentioned in Installation section. And due to the code of the core sinon.js file only in Node.js environment it is done automatically.
这篇关于类型错误:“未定义”是不是(评估'sinon.spy()')函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!