访问props().x返回undefined



我正在使用create-react应用程序typescript启动器,我注意到道具不起作用。我做错什么了吗?

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

这就是我犯的错误。

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

使用prop((而不是props((

最新更新