React Jest Test Failing - type.toUpperCase不是一个函数

时间:2016-04-23 15:16:08

标签: javascript reactjs jestjs

我正在尝试使用JestReact编写测试。但是,我收到以下错误:

  

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');
    });
});

1 个答案:

答案 0 :(得分:0)

从以下位置重新定义您的React组件:

export class Images extends Component {...}

为:

var Images = React.createClass ({...)};
module.exports = Images;