我使用的是create-react-app打字机启动器,但我发现道具无法正常工作。我在做错什么吗?
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:
答案 0 :(得分:0)
it("should not render without x", () => {
expect(wrapper.prop('x')).toBe(0);
});
使用prop()代替props()