gpt4 book ai didi

javascript - 开 Jest : Cannot set property 'props' of undefined

转载 作者:行者123 更新时间:2023-12-02 14:44:12 24 4
gpt4 key购买 nike

我正在开始学习 Jest,并且创建了这个测试。但是当我运行它时,我收到下面的消息。

我是否以错误的方式将 props 传递给 AppComponent?

TypeError: Cannot set property 'props' of undefined

应用程序.js:

const { store } = this.props;

return (
<div>
<h2 className={css(styles.hover)}>Welcome to the { store.name } project!</h2>
<h3>This project is { store.description }.</h3>
<MyComponent store={store} />
</div>
);

应用程序测试.js:

const storeProp = {
name: 'Reaxor',
description: 'Hello'
}

describe('App', () => {
it('returns the correct text', () => {

// Render a checkbox with label in the document
const app = TestUtils.renderIntoDocument(
<App store={storeProp} />
);

const appNode = ReactDOM.findDOMNode(app);

const h2 = TestUtils.findRenderedDOMComponentWithTag(app, 'h2')
const h3 = TestUtils.findRenderedDOMComponentWithTag(app, 'h3')

expect(h2.textContent).toEqual('Welcome to the Reaxor project!');
expect(h3.textContent).toEqual('This project is Hello.')
});
});

最佳答案

在我看来,有些东西被 mock 了,但不应该被 mock 。您可以尝试在配置中禁用自动模拟 "automock": false 并查看该模型是否更适合您:)

关于javascript - 开 Jest : Cannot set property 'props' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36753305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com