J'ai un test Mocha-chai sur un composant React connecté Redux. Pour passer le magasin Redux au composant de test, je crée dans le fichier de test et de le transmettre comme un accessoire, mais le test jette l'erreur suivante:Réagir Mocha-chai test ne pas reconnaître magasin de prop
Invariant Violation: Could not find "store" in either the context or props of "Connect(Project)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Project)".
Voici le test:
import React from 'react';
import ReactDOM from 'react-dom';
import {
renderIntoDocument,
scryRenderedComponentsWithType
} from 'react-dom/test-utils';
import Project from '../../src/components/Project';
import { expect } from 'chai';
import { createStore } from 'redux';
import reducer from '../../src/reducers/reducers';
const store = createStore(reducer);
const component = renderIntoDocument(
<Project
store={ store }
project={
{
"name": "MyName",
"img": "path.jpg",
"img_alt": "alt desc",
"description": "lorem ipsum",
"github": "repository",
"link": "website.com"
}
} />
);
describe('Project',() => {
// tests ...
});
Ceci est le composant React:
import React from 'react';
import ProjectImage from './ProjectImage';
import ProjectText from './ProjectText';
import { connect } from 'react-redux';
import * as actions from '../actions/actions';
export const Project = React.createClass({
getProject: function() {
return this.props.project || {};
},
handleClick: function(event) {
this.props.dispatch(actions.showModal(true));
this.props.dispatch(
actions.setModalContent(this.getProject())
);
},
render: function() {
return (
<div className="project">
<ProjectImage
img={ this.getProject().img }
imgAlt={ this.getProject().img_alt }
link={ this.getProject().link } />
<ProjectText
projectName={ this.getProject().name }
tagline={ this.getProject().tagline }
description={ this.getProject.description }
github={ this.getProject().github }
webLink={ this.getProject().link }
openModal={ this.handleClick } />
</div>
);
}
});
export default connect()(Project);
pouvez-vous essayer en utilisant 'Provider' et en passant le magasin. – nrgwsth
' ' –
nrgwsth
Oui, j'ai essayé d'ajouter le fournisseur et de passer le magasin. Même erreur – mhatch