[英]Why am I getting 'undefined:x:y : property' missing error when running jest tests?
I am using jest & styled-components, or more specificallyjest-styled-components for testing.我正在使用 jest & styled-components,或更具体地说是jest-styled-components进行测试。
I have made changes to a component called FormField , which used the component Form , when running the tests, I am getting the following error.我对一个名为FormField的组件进行了更改,该组件使用了组件Form ,在运行测试时,我收到以下错误。
undefined:42:16: property missing ':'
31 | );
32 | const tree = component.toJSON();
> 33 | expect(tree).toMatchSnapshot();
| ^
34 | });
35 |
36 | test('update', () => {
The jest test is as following开玩笑的测试如下
test('with field', () => {
const component = renderer.create(
<Grommet>
<Form>
<FormField name="test" />
</Form>
</Grommet>,
);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
I can't pinpoint what the problem is, the changes I made to the component did not show any errors, and I'm getting the same errors in the testing of FormField component.我无法确定问题是什么,我对组件所做的更改没有显示任何错误,并且我在测试 FormField 组件时遇到了同样的错误。
I have fixed the problem.我已经解决了这个问题。 The problem was caused because I did not update the snapshot after the changes I made to the component.问题是因为我在对组件进行更改后没有更新快照。
It can be done with它可以用
jest --updateSnapshot or jest --u
The problem might be with the CSS you are using.问题可能出在您使用的 CSS 上。 I had the same issue and removing the CSS values in px and rem fixed the issue.我遇到了同样的问题,删除了 px 和 rem 中的 CSS 值解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.