1
我正在嘗試使用Jest
編寫測試用於React
。不過,我發現了以下錯誤:反應Jest測試失敗 - type.toUpperCase不是函數
TypeError: type.toUpperCase is not a function
陣營(images.js):
import React, { Component } from 'react';
export class Images extends Component {
render() {
return (
<div class="images">
</div>
);
}
}
測試(玩笑):
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');
});
});
你在哪裏調用'toUpperCase()'函數?您的問題中沒有提供該部分代碼。 –
我不是,這是問題。我已經修改了它,通過改變我定義我的React組件的方式,使用var Images = React.createClass({'代替export class,然後在底部添加'module.exports = Images;' – DorianHuxley