2016-06-06 2 views
0

나는 here 튜토리얼을 통해 작업하고 있는데, 처음에는 대부분의 기본적인 chai 테스트가 실패한 것으로 나타났습니다. 여기일관성있게 실패하는 Chai/Mocha 불변의 테스트

import {List} from 'immutable'; 

export function setEntries(state, entries){ 
    return state.set('entries', entries); 
} 

실패 오류 메시지입니다 :

1) application logic setEntries adds the entries to the state: 

     AssertionError: expected { Object (size, _root, ...) } to equal { Object (size, _root, ...) } 
     + expected - actual 

       "size": 2 
       } 
      ] 
      ] 
     - "ownerID": [undefined] 
     + "ownerID": {} 
     } 
     "size": 1 
     } 

는 '내가 할 수있는 여기 여기

import {List, Map} from 'immutable'; 
import {expect} from 'chai'; 

import {setEntries} from '../src/core'; 

describe('application logic',() => { 
    describe('setEntries',() => { 
     it('adds the entries to the state',() => { 
      const state = Map(); 
      const entries = List.of('Trainspotting', '28 Days Later'); 
      const nextState = setEntries(state, entries); 
      expect(nextState).to.equal(Map({ 
       entries: List.of('Trainspotting', '28 Days Later') 
      })); 
     }); 
    }); 
}); 

하고 실패한 테스트에 대한 현재의 예에 대한 코드를 테스트입니다 이 오류의 의미에 대한 의미있는 문서를 찾은 것 같으며 비슷한 문제를 언급하는이 자습서의 다른 사용자는 보지 못합니다. 이게 질식하는 곳이면 어떨까요?

답변

2

변경할 수없는 개체에 대해서는 일반 항등 검사를 사용할 수 없습니다. 대신, Immutable.is() 같은 것을 사용

import Immutable, {List, Map} from 'immutable'; 

... 

expect(
    Immutable.is(nextState, Map({ 
    entries: List.of('Trainspotting', '28 Days Later') 
    })) 
).to.be.true; 

심지어 더 나은, chai-immutable를 사용

import chai, {expect} from 'chai'; 
import chaiImmutable from 'chai-immutable'; 

chai.use(chaiImmutable); 

을 후자, 테스트 케이스와 동일하게 유지 할 수 있습니다.

0

파일의 시작 부분에 아래 코드를 추가해야합니다.

import chai from 'chai'; 
import chaiImmutable from 'chai-immutable'; 

chai.use(chaiImmutable);