chai-redux-mock-store - ReferenceError:未定义createMockStore

时间:2018-02-23 20:01:37

标签: reactjs redux chai

我关注https://www.npmjs.com/package/chai-redux-mock-store上的示例,并且不明白为什么createMockStore未定义。

的package.json

  "scripts": {
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js 'test/**/*.@(js|jsx)'",
    "test:watch": "npm run test -- --watch"
  },

测试/ test_helper.js

import chai from 'chai';
import chaiReduxMockStore from 'chai-redux-mock-store';

chai.use(chaiReduxMockStore);

测试/组件/登录/ Login_spec.jsx

const store = createMockStore();

npm run test

ReferenceError: createMockStore is not defined

修正

import {Provider} from 'react-redux';

const createMockStore = (getState) => {
    const middlewares = [];
    return configureStore(middlewares)(getState);
};

const store = createMockStore();

const component = renderIntoDocument(
   <Provider store={store}>
      <LoginContainer />
   </Provider>
);

0 个答案:

没有答案