[英]accessing props().x returns undefined
I'm using the create-react-app typescript starter and I noticed props are not working. 我正在使用create-react-app打字稿启动器,但发现道具无法正常工作。 Am I doing something wrong?
难道我做错了什么?
import * as enzyme from "enzyme";
import * as React from "react";
import Box from "./Box";
describe("Box component", () => {
let wrapper: any;
beforeEach(() => {
wrapper = enzyme.shallow(<Box x={0} y={2} />);
});
it("should not render without x", () => {
expect(wrapper.props().x).toBe(0);
});
});
And this is the error I'm getting. 这就是我得到的错误。
expect(received).toBe(expected) // Object.is equality
Expected value to be:
0
Received:
undefined
Difference:
it("should not render without x", () => {
expect(wrapper.prop('x')).toBe(0);
});
Use prop() instead of props() 使用prop()代替props()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.