我按照此链接'https://github.com/airbnb/enzyme/blob/master/docs/api/shallow.md'编写单元测试,如下所示:
import { shallow } from 'enzyme';
import React from 'react';
import TextField from 'material-ui/TextField'
describe('Question Test Suite', () => {
it('should render one <TextField/> components', () => {
const wrapper = shallow(<QuestionForm />, { context: {router: {} }});
expect(wrapper.find(TextField)).to.have.length(1);
});
});
运行测试用例时我得到以下错误:
TypeError: expect(...).length is not a function
TypeError: Cannot read property 'have' of undefined
我的测试用例有什么问题?那里有什么我想念的吗?
答案 0 :(得分:1)
您的语法错误。以下语法应该可以正常工作。
expect(wrapper.find('TextField').length).toEqual(1);