依序 Sinon-Chai 斷言

Build Status

Dependency Status devDependency Status

動機

Sinon-ChaiSinon.JS 提供 Chai 斷言。可惜的是,它沒有處理確保間諜(spy)以特定順序被多次呼叫。這可能會導致笨拙、不流暢的斷言。

var spy = sinon.spy();
[1, 2, 3].forEach(spy);
expect(spy.getCall(0).args[0]).to.equal(1);
expect(spy.getCall(1).args[0]).to.equal(2);
expect(spy.getCall(2).args[0]).to.equal(3);

使用 sinon-chai-in-order,您可以這樣說

expect(spy).inOrder.to.have.been.calledWith(1)
                   .subsequently.calledWith(2)
                   .subsequently.calledWith(3);

設定

在 Node 中,只需使用 npm 安裝即可

$ npm install sinon-chai-in-order

在您的測試中,讓 Chai 使用此外掛。請確保您也使用了 sinon-chai,否則巢狀斷言將無法運作。

import chai, {expect} from 'chai';
import sinonChai from 'sinon-chai';
import sinonChaiInOrder from 'sinon-chai-in-order';

chai.use(sinonChai);
chai.use(sinonChaiInOrder);

此外掛以 UMD 格式分發,因此您可以在任何地方使用它。然而,它是作為 ES6 模組匯出的。如果使用 ES5,請使用

chai.use(require('chai-react-element').default);

貢獻

設定

此專案使用 Gulp 進行建置和測試,並使用 webpack-dev-server 在瀏覽器中執行和偵錯。要安裝專案,只需執行 npm install。

要啟動開發環境,請執行 npm start,或者,如果您已全域安裝 Gulp,請執行 gulp dev。這會使用 Mocha 執行測試,並額外在 8080 埠啟動 webpack-dev-server。要執行測試,請使用 npm test (或 gulp test)。

問題

對於您可能發現的任何問題,請在專案的 GitHub 儲存庫上開啟一個 issue。在 issue 中討論您的問題之前,請不要建立 pull request。

Pull Request

請嘗試使用測試驅動開發來開發您的提交內容。至少,請確保您的變更透過測試良好地涵蓋,並且您的程式碼是乾淨的。