我正在尝试使用Jest
为React
编写测试。但是,我收到以下错误:
TypeError: type.toUpperCase is not a function
React(images.js):
import React, { Component } from 'react';
export class Images extends Component {
render() {
return (
<div class="images">
</div>
);
}
}
测试(Jest):
jest.autoMockOff();
import React from 'react';
import TestUtils from 'react-addons-test-utils';
const ImagesComponent = require('../src/Components/images');
describe('ImagesComponent', () => {
it('Render instance of div class=images in DOM', () => {
const shallowRenderer = TestUtils.createRenderer();
shallowRenderer.render(<ImagesComponent className="images" />);
imagesDivComponent = shallowRenderer.getRenderOutput();
expect(imagesDivComponent.props.className).toEqual('images');
});
});
答案 0 :(得分:0)
从以下位置重新定义您的React组件:
export class Images extends Component {...}
为:
var Images = React.createClass ({...)};
module.exports = Images;