酶 - 不变违规:无法找到“商店”

时间:2018-04-04 14:31:51

标签: reactjs redux enzyme

我正在尝试测试组件的DISCONNECTED版本。出于某种原因,Enzyme抱怨商店。我不知道为什么。我导入了断开连接的版本。

这是我的测试:

import { Board } from '../components/Board/Board'; 
import { shallow, mount } from 'enzyme'; 
import { Redirect } from 'react-router-dom';
import { BrowserRouter as Router } from 'react-router-dom'; 

describe('Board', () => {
    it('contains .board when currentBoardId is truthy', () => {
        const wrapper = mount(<Router><Board currentBoardId={true} /></Router>); 
        expect(wrapper.contains(<Redirect to="/navigation" />)).toEqual(false); 
    }); 
}); 

这是我的组件:

import React from 'react'; 
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import BoardForm from '../BoardForm/BoardForm';
import BoardToDos from '../BoardToDos/BoardToDos';   
import BoardCompleted from '../BoardCompleted/BoardCompleted'; 
import './Board.css';  

export class Board extends React.Component {
    render() {

        if(!this.props.currentBoardId) {
            return (
                <Redirect to="/navigation" />
            )
        }
        return (
            <div className="board">
                <BoardForm />
                <BoardToDos />
                <BoardCompleted />
            </div>
        )
    }
}

const mapStateToProps = state => ({
    currentBoardId: state.currentBoardId
}); 

export default connect(mapStateToProps)(Board); 

这是错误:

Invariant Violation: Could not find "store" in either the context or props of "Connect(BoardForm)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(BoardForm)"

我不明白为什么它告诉我这家商店。我导入了断开连接的版本。救命?

0 个答案:

没有答案