简体   繁体   English

为什么在运行玩笑测试时出现“未定义:x:y:属性”缺失错误?

[英]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.

相关问题 当我可以打印未定义的变量时,为什么会出现“无法读取未定义错误的属性”? - Why Am I Getting “Cannot read property of undefined error” When I Can Print the Undefined Variable? 为什么在属性列表错误后我会丢失这个 }? :( - Why am i getting this missing } after property list error? :( 为什么我会收到“无法设置未定义的属性 'border'”错误? - Why am I getting the “Cannot set property 'border' of undefined” error? 为什么我越来越无法读取未定义错误的属性? - why I am getting, cannot read property of undefined error? 为什么我收到“无法设置未定义的属性”的错误? - Why am i getting error of “cannot set property of undefined”? 使用Arangodb运行Jest测试时缺少模块 - Missing module when running Jest tests with Arangodb 我正在尝试为索引 [arr[i][j]]['x'] 分配值,我收到无法设置属性 'x' 的未定义错误 - I am trying to assign value for index[arr[i][j]]['x'], i am getting the Cannot set property 'x' of undefined error 为什么我在运行时收到此错误:npm run build? - Why am I getting this error when running: npm run build? 为什么在运行我的代码时会收到错误“UnhandledPromiseRejectionWarning”? - Why am I getting error "UnhandledPromiseRejectionWarning" when running my code? 为什么会出现未定义的错误? - why am I getting an undefined error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM