powOfTwo.js代碼exports.judge = function (a) {
if(a == 2) { return true;
} if(a % 2) { return false;
}else {
a = a / 2; return judge(a);
}
}測試代碼:var powerOfTwo = require('../powerOfTwo.js');
describe('basic test', function(){
it('test sample', function() {
expect(powerOfTwo.judge(16)).toBe(true);
expect(powerOfTwo.judge(12)).toBe(false);
expect(powerOfTwo.judge(1024)).toBe(true);
})
})報錯:$ jasmine-node powerOfTwo-spec.jsFFailures:
1) basic test test sample Message: ReferenceError: judge is not defined Stacktrace:
ReferenceError: judge is not defined at Object.exports.judge (D:\vanilla-javascript\powerOfTwo.js:9:16)
at .<anonymous> (D:\vanilla-javascript\spec\powerOfTwo-spec.js:5:27)Finished in 0.065 seconds1 test, 1 assertion, 1 failure,
0 skipped
jasmine-node寫單元測試方法not defined的問題
千萬里不及你
2018-09-07 10:05:40