我正在尝试使用Jest运行测试,但是我收到以下错误,我不太确定原因:
Running 1 test suite...Warning: Component(...): No `render` method found on the returned component instance: you may have forgotten to define `render`, returned null/false from a stateless component, or tried to render an element whose type is a function that isn't a React component.
FAIL __tests__\images-test.js (0.867s)
● Images › it encountered a declaration exception
- TypeError: inst.render is not a function
我正在使用babel-core& loader ^ 6.0.0,babel-jest ^ 11.0.2
这是我的Jest Test文件:
jest.autoMockOff();
import React from 'react';
import ReactDOM, { render } from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Images from './../src/Components/images';
describe('Images', () => {
let mockData = {
items: [
{
title: 'Test Title',
media: {
m: 'http://www.testurl.com/test.jpg'
}
},
{
title: '2nd Test Title',
media: {
m: 'http://www.testurl.com/test2.jpg'
}
}
],
selectedImages: [],
selectImage() { return false; }
}
const shallowRenderer = TestUtils.createRenderer();
shallowRenderer.render(<Images
items={mockData.items}
selectedImages={mockData.selectedImages}
selectImage={mockData.selectImage} />);
it('Renders instance of div class=images in DOM', () => {
expect(shallowRenderer.getRenderOutput().props.className).toEqual('images');
});
it('Renders child elements', () => {
expect(shallowRenderer.getRenderOutput().props.children.length).toBeGreaterThan(0);
});
});
任何帮助都将不胜感激。