我想在我的ember-cli應用程序中使用sinon,我無法弄清楚如何導入它。我在規範import語句:如何將sinon導入ember-cli測試?
import { sinon } from '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模塊,因此對這些作品的背景鏈接將不勝感激。謝謝!
要擺脫jshint錯誤,您必須將「sinon」添加到「tests/.jshintrc」中的predef數組中。不是項目寬「.jshintrc」!應該看起來像{「predef」:[「sinon」]}; – phlppn
感謝@phlppn,這正是jshint的問題。 – spinlock