类型错误:“未定义”是不是(评估'sinon.spy()')函数 [英] TypeError: 'undefined' is not a function (evaluating 'sinon.spy()')

查看:192
本文介绍了类型错误:“未定义”是不是(评估'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:


  1. 创建与骨干自耕农发电机
  2. 空项目
  3. 安装兴农: CD测试&放大器;&安培;亭子安装兴农

  4. 在测试包含/ index.html的< SCRIPT SRC =bower_components /兴农/ lib目录/ sinon.js>< / SCRIPT>

  5. 创建测试/规格/ test.js间谍:

  1. Create an empty project with backbone yeoman generator
  2. Install sinon: cd test && bower install sinon
  3. Include in test/index.html <script src="bower_components/sinon/lib/sinon.js"></script>
  4. 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屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆