【发布时间】:2018-05-21 22:51:19
【问题描述】:
我正在尝试测试 Redux 操作,但我在终端中收到此错误:
AssertionError: expected { type: 'LOG_IN', email: 'email' } to equal { type: 'LOG_IN' , email: 'email' } + 预期 - 实际
问题:这两个对象似乎是相等的,它们具有相同的属性和相同的值。我希望他们是平等的。但它们被报告为不相等。
myActions.js
import { LOG_IN,LOG_OUT } from './actionTypes';
export function logIn(email) {
return {
type: LOG_IN,
email: email
};
}
userReducer.test.js
import * as actions from '../actions/userActions';
import * as types from '../actions/actionTypes';
import user from '../reducers/userReducer';
describe('user login reducer test', () => {
it('should update initialState to include email', () => {
const email = 'email'
const expectedAction = {
type: LOG_IN,
email: 'email'
}
const result = actions.logIn(email);
expect(result).to.equal(expectedAction);
})
})
actiontypes.js
export const LOG_IN = 'LOG_IN';
export const LOG_OUT = 'LOG_OUT';
【问题讨论】:
-
更改标题以更准确地反映问题。就像“Redux - 看似相等的对象并不相等”。
标签: javascript reactjs unit-testing redux jestjs