Enzyme의 mount
을 사용하여 여러 Material UI 구성 요소가 중첩 된 내 구성 요소를 테스트하려고합니다. 테스트를 실행할 때이 오류를 얻을 :Material UI 구성 요소를 포함하는 구성 요소를 테스트하기 위해 Enzyme 마운트 방법으로 컨텍스트를 전달하는 방법은 무엇입니까?
TypeError: Cannot read property 'prepareStyles' of undefined
을 뒷조사 한 후, I did found that a theme needs to be passed down in a context. 테스트에서 그렇게하고 있지만 여전히이 오류가 발생합니다.
내 시험 :
import expect from 'expect';
import React, {PropTypes} from 'react';
import {mount} from 'enzyme';
import SearchBar from './SearchBar';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
function setup() {
const muiTheme = getMuiTheme();
const props = {
closeSearchBar:() => {},
fetchSearchData:() => {},
data: [],
searching: false
};
return mount(<SearchBar {...props} />, {context: {muiTheme}});
}
describe('SearchBar Component',()=> {
it('Renders search toolbar properly',() => {
const wrapper = setup();
expect(wrapper.find('.toolbar').length).toBe(1);
expect(wrapper.find('button').length).toBe(1);
});
});
내 검색 창 구성 요소가 비 저장 구성 요소입니다, 그래서 어떤 상황에서 당기는하고 있지 않다. 그러나 내가있을 때조차도 나는 여전히 같은 오류를 낳는다.
내가 뭘 잘못하고 있니? mount
옵션에 childContextTypes
을 추가
네, 정확히 그게 빠져있었습니다. 'contextTypes : {muiTheme : React.PropTypes.object}'를 전달하려했으나 React 컨텍스트를 조금 더 살펴 봐야 겠지만'childContextTypes'는 안됩니다. 감사합니다. Nicolas! – Erika
같은 '얕은'함께 작동, 그냥 얕은 의해 마운트를 대체하십시오. –
감사합니다. 나는 그게 그렇게 간단하지 않다고 믿을 수 없다. 나는 이미 필자가 테스트 한 컴포넌트를 redux 스토어 제공 업체에 포장해야한다는 사실을 인정했다. – gustavohenke