1
我想在被測試的js中使用module.exports並使用require()將其包含到規範腳本中。在jasmine規範中使用module.exports
cat.js - 與目標文件,我想出口
var cat = {
name: "filemon",
meow: function() {
return "miau";
},
walk: function() {
return "siup siup siup";
}
}
module.exports = cat
catTest.js - 規格貓
var cat = require('../app/cat')
describe("Cat test", function() {
it("cat should meow with miau", function() {
expect(cat.meow()).toBe("miau")
})
})
當我運行使用茉莉CLI測試(用npm下載)測試通過:
marcins-iMac:untitled marcin$ jasmine
Started
..
2 specs, 0 failures
Finished in 0.004 seconds
但是當我嘗試運行與人緣轉輪模塊未定義測試:
marcins-iMac:untitled marcin$ karma start
29 04 2016 23:52:29.238:WARN [karma]: No captured browser, open http://localhost:9876/
29 04 2016 23:52:29.248:WARN [karma]: Port 9876 in use
29 04 2016 23:52:29.248:INFO [karma]: Karma v0.13.22 server started at http://localhost:9877/
29 04 2016 23:52:29.252:INFO [launcher]: Starting browser Chrome
29 04 2016 23:52:30.112:INFO [Chrome 50.0.2661 (Mac OS X 10.11.2)]: Connected on socket /#MJ-R1hm8uQEvSJq9AAAA with id 29613373
Chrome 50.0.2661 (Mac OS X 10.11.2) ERROR
Uncaught ReferenceError: module is not defined
at /Users/marcin/WebstormProjects/untitled/app/cat.js:9
一些想法,我並沒有幫助:
- 加入require.js「文件」中的業力.config.js
- 附加測試對象窗口範圍(它與CLI難看和不工作)
如果問題可被C引起github上的項目:https://github.com/marcinmierzejewski1024/jasmine-karma-playground