Javascript Chai/Mocha不可变测试持续失败
我正在学习教程,发现除了最初级的chai考试外,几乎所有的考试都不及格。下面是失败测试的当前示例Javascript Chai/Mocha不可变测试持续失败,javascript,reactjs,mocha.js,chai,immutable.js,Javascript,Reactjs,Mocha.js,Chai,Immutable.js,我正在学习教程,发现除了最初级的chai考试外,几乎所有的考试都不及格。下面是失败测试的当前示例 import {List, Map} from 'immutable'; import {expect} from 'chai'; import {setEntries} from '../src/core'; describe('application logic', () => { describe('setEntries', () => { it('ad
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')
}));
});
});
});
下面是针对以下各项进行的代码测试:
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 chai from 'chai';
import chaiImmutable from 'chai-immutable';
chai.use(chaiImmutable);
您必须在文件开头添加以下代码
import chai from 'chai';
import chaiImmutable from 'chai-immutable';
chai.use(chaiImmutable);
import chai from 'chai';
import chaiImmutable from 'chai-immutable';
chai.use(chaiImmutable);