我正在尝试在我的 ember-cli 应用程序中使用 sinon,但我不知道如何导入它。我在规范中有一个导入声明:
import { sinon } from 'sinon';
然后我尝试在测试中使用 sinon:
it('finds the todo model', function () {
var store = this.subject().store;
var spy = sinon.spy(store, 'find');
this.subject().model();
expect(spy).to.have.been.called;
});
但是,当我从命令行运行时,出现ember test
此错误:
not ok 8 PhantomJS 1.9 - TestLoader Failures my-app/tests/unit/routes/application-test: could not be loaded
---
message: >
Could not find module `sinon` imported from `my-app/tests/unit/routes/application-test`
stack: >
Error: Could not find module `sinon` imported from `my-app/tests/unit/routes/application-test`
at requireFrom (http://localhost:7357/assets/vendor.js:119)
at reify (http://localhost:7357/assets/vendor.js:106)
at http://localhost:7357/assets/vendor.js:149
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:13918
Log: >
...
我注意到的一件事是目录ember-sinon
中的足迹非常轻bower_components/
:
$ls bower_components/sinon/
index.js
我已经尝试将导入行更改为,import { sinon } from 'sinon/index';
但这也没有奏效。
任何帮助将不胜感激。我对 ember-cli、bower 和 es6 模块非常陌生,因此非常感谢这些模块的背景链接。谢谢!