使用Mocha進行測試時,如何加載foo.js以便foo-test.js可以測試諸如giveMeFive()之類的全局變量?如何用Mocha測試全局變量?
foo.js:
function giveMeFive() {
return 'High five!');
}
FOO-test.js:
describe('#convertNumberToDollar()', function() {
it('should get a successful high five',() => {
assert.ok(giveMeFive() === 'High five!', ' successful high five.');
});
});
這將是理想的,如果該解決方案可以通過竹被自動化。
你在節點中運行摩卡嗎?在這種情況下,你可以使用'require'(或者如果你使用Babel則使用'import') –
即使giveMeFive()是全局的嗎? –
現在查看我的答案。 –