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.js
F
Failures:
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 . (D:\vanilla-javascript\spec\powerOfTwo-spec.js:5:27)
Finished in 0.065 seconds
1 test, 1 assertion, 1 failure, 0 skipped
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你
powOfTwo.js的最后一个else引用变量judge。感觉不是 else 里面递归调用
judge的事儿。只用
exports应该是不会 export function 的。。试试用module.exports直接 export