儘可能不要在 describe
及 it
中使用 require
。
例如:
const chai = require('chai');
const MyClass = require('../src/my-class');
describe('The Auth module', () => {
// …
});
it
是待測目標的代稱,故 it
後面要接行為的描述。
it('should get user data after user logged-in', () =>
// ...
});
因為 mocha 支援 promise ,所以應該使用 promise 回傳。
以回傳 promise 為優先,除非情境很難用 promise ,才考慮使用 done 。
以語意優先,所以 assertion 一律使用 should ,除非有 should 無法使用的場合,才用 expect 。
這樣 spy 做完事後,就無法被 sinon.assert
驗證了。
確保每個測試案例執行前後該做的事都有做完,除非無法使用 promise 才考慮呼叫 done()
。
好奇所說的不是用 done
一般不是最後要 done 測試才算結束?