chai-immutable 外掛

  1. 從 npm chai,chai-immutable 和 ts-node 安裝

    npm install --save-dev chai chai-immutable ts-node
    
  2. 安裝 mocha 和 chai 的型別

    npm install --save-dev @types/mocha @types/chai
    
  3. 寫簡單的測試檔案:

      import {List, Set} from 'immutable';
      import * as chai from 'chai';
      import * as chaiImmutable from 'chai-immutable';
    
      chai.use(chaiImmutable);
    
      describe('chai immutable example', () => {
        it('example', () => {
          expect(Set.of(1,2,3)).to.not.be.empty;
    
          expect(Set.of(1,2,3)).to.include(2);
          expect(Set.of(1,2,3)).to.include(5);
        })
      })
    
  4. 在控制檯中執行它:

    mocha --compilers ts:ts-node/register,tsx:ts-node/register 'test/**/*.spec.@(ts|tsx)'