導出類我已經正在由茉莉節點在一個文件中運行下面的測試代碼中調用bob_test.spec.js
與node.js的
require('./bob');
describe("Bob", function() {
var bob = new Bob();
it("stating something", function() {
var result = bob.hey('Tom-ay-to, tom-aaaah-to.');
expect(result).toEqual('Whatever');
});
});
爲了使測試通過,我已經寫了下面的生產在一個文件中的代碼調用bob.js
"use strict";
var Bob = function() {
}
Bob.prototype.hey = function (text) {
return "Whatever";
}
module.exports = Bob;
當我運行測試 - 採用jasmine-node .
- 我得到以下 ˚F
Failures:
1) Bob encountered a declaration exception
Message:
ReferenceError: Bob is not defined
Stacktrace:
ReferenceError: Bob is not defined
at null.<anonymous> (/Users/matt/Code/oss/deliberate-practice/exercism/javascript/bob/bob_test.spec.js:4:17)
at Object.<anonymous> (/Users/matt/Code/oss/deliberate-practice/exercism/javascript/bob/bob_test.spec.js:3:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Finished in 0.02 seconds
1 test, 1 assertion, 1 failure, 0 skipped
基於我對JavaScript的理解,我覺得這應該起作用。 node.js與構造函數和模塊導出有什麼不同,它阻止了它的運行我喜歡它應該這樣做?
太好了!這是一個挽救生命的問題 –