0
所以我想我創建了一個簡單的測試來確認我爲我的redux減速器設置了mocha/chai測試,但是這個初始測試由於我無法辨別的原因而失敗。一切都根據babel docs設置。沒有es6相關的錯誤。爲什麼摩卡測試減速機失敗?
文件結構
client
|-reducers
| |-auth_reducer.js
|
test
|-reducers
| |-auth.test.js
測試腳本
mocha --compilers js:babel-register --require babel-polyfill --recursive
驗證減速
const AUTH_USER = 'AUTH_USER';
const INITIAL_STATE = { error: '', message: '', content: '', authenticated: false, user: null };
export default function (state = INITIAL_STATE, action) {
switch (action.type) {
case AUTH_USER:
return { ...state, error: '', message: '', authenticated: true };
}
return state;
}
驗證測試
import { expect } from 'chai';
import authReducer from '../../client/reducers/auth_reducer';
describe('auth_reducer',() => {
it('handles AUTH_USER',() => {
const initialState = {
error: '',
message: '',
content: '',
authenticated: false,
user: null
};
const action = {
type: 'AUTH_USER',
};
const nextState = authReducer(initialState, action);
expect(nextState).to.equal({
error: '',
message: '',
content: '',
authenticated: true,
user: null
});
});
});
錯誤
auth_reducer
1) handles AUTH_USER
0 passing (38ms)
1 failing
1) auth_reducer handles AUTH_USER:
AssertionError: expected { Object (error, message, ...) } to equal { Object (error, message, ...) }
+ expected - actual
at Context.<anonymous> (test/reducers/auth.test.js:20:26)
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
npm ERR! node v6.7.0
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test: `mocha --compilers js:babel-register --require babel-polyfill --recursive`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script 'mocha --compilers js:babel-register --require babel-polyfill --recursive'.
神聖的上帝謝謝。我會去谷歌的原因。 – Kwhitejr
我用一個簡單的例子添加了「爲什麼」。 –