TypeError:无法读取属性' removeItem'未定义的

时间:2018-03-09 07:27:54

标签: javascript reactjs unit-testing mocha

我正在学习在ReactJs中编写单元测试用例以及新的。我得到" TypeError:无法读取属性' removeItem'未定义"使用mocha在ReactJs中运行测试用例时出错。我经历了一些链接,但我没有找到任何解决方案。我该如何解决这个问题? 在这里,我附上我的测试用例。提前谢谢。

import React from 'react';
import sinon from 'sinon';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import createRouterContext from 'react-router-test-context';
import { createStore } from 'redux';
import reducers from '../../../../src/reducers/RootReducer';
import { token } from '../../../Token';
import '../../../../static/js/jquery.slimscroll.js';
import configureStores from '../../../../src/store/configureStore';
import EditDevice from '../../../../src/components/rightComponents/projectManagementComponents/EditDevice';

const routerObj = Object.assign(createRouterContext().router.history, { go: spy(), goBack: spy(), goForward: spy(), setRouteLeaveHook: spy(), isActive: spy() });
const CONTEXT_TYPE = { router: routerObj };
const CHILD_CONTEXT_TYPE = {
    router: React.PropTypes.object,
};
localStorage.setItem('token', token);
const initialState = {
    reviewStageData: {
        deviceData: {
            wmi_status: 'Success',
            core: '2',
            disk_count: 1,
            disk_drive: 2,
            os_type: 'Others',
            role_names: 'Server',
            storage_type: '',
            totalstorage: '2.0',
            used_storage: '129.74',
        },
        sectionName: 'device',
        osList: 'windows 7',
        dummyFlag: 'true',
    },
};

describe('CHECKING EDITDEVICE', () => {
    localStorage.setItem('token', token);

    let store,
        wrapper;
    const mockStore = configureStore();
    const myspy = spy(EditDevice.prototype, 'componentDidMount');
    beforeEach(() => {
        store = mockStore(initialState);
        const routeParams = {
            client_id: 177,
        };
        wrapper = mount(
            <Provider store={store}>
                <EditDevice routeParams={routeParams} />
            </Provider>
        ).setState({ devicedata: deviceData });
    });
    afterEach(() => {
        myspy.restore();
    });
    it('<==== Checking wheather EditDevice mounted ====>', () => {
        expect(EditDevice.prototype.componentDidMount.calledOnce).toEqual(true);
    });
});

0 个答案:

没有答案