如何测试导入redux商店的功能?
这是导入redux商店的功能。
// getLabel.test.js
import getLabel from './getLabel';
import { createMockStore } from 'redux-test-utils';
let mockLabel = {
add_filter: {
en: "Add Filter",
cn: "添加過濾器"
}
}
let mockLabels = {
labels: {
language: "en",
label: mockLabel
}
};
let store = createMockStore(mockLabels);
const action = {
type: 'GET_LABELS',
labels: mockLabels
};
describe('example', () => {
it('works', () => {
store.dispatch(action);
expect(store.getAction(action.type)).toEqual(action);
expect(store.getActions()).toEqual([action]);
expect(store.isActionDispatched(action)).toBe(true);
expect(store.isActionTypeDispatched(action.type)).toBe(true);
expect(store.getState()).toBe(mockLabels);
expect(getLabel('This label does not exist')).toBe('This label does not exist');
expect(getLabel('add filter')).toBe('Add Filter');
});
});
这是我的单元测试
JMSDestination
最后一次测试失败,因为正在使用的商店是在getLabel.js中导入的