這是我第一次嘗試使用摩卡和柴,並且我創建了這個小測試文件test.spec.js
,我在其中放置了一些測試。用摩卡和柴測試
var expect = require('chai').expect;
var foo = 'bar';
describe('Test', function() {
it('Should exist', function() {
expect(foo).to.exist;
});
it('Should be a string', function() {
expect(foo).to.be.a('string');
});
it('Should equal bar', function() {
expect(foo).to.equal('bar');
});
it('Should be at least 3 chars', function() {
expect(foo).to.have.length.above(2);
});
});
這是在一個單獨的文件中,我有我的「主要」代碼。
但我該如何去測試我在腳本文件中寫入的實際相關代碼?
我沒有使用ES6,所以我無法導入或需要。但我使用npm,這就是我需要chai的原因。
所以,我的計劃是這樣的
A folder
- myscript.js
- test.spec.js
如何測試的MyScript?
可以添加myscript.js文件 –
你使用任何腳本加載器? – Thaadikkaaran