【问题标题】:Can't log the value of an enzyme shallow wrapper in react-native jest无法在 react-native jest 中记录酶浅包装器的值
【发布时间】:2018-04-27 13:35:31
【问题描述】:

使用 React Native、jest 和酶,我什至无法检查浅渲染组件的值,更不用说在其上运行测试断言了。

Enzyme 和 jest 在其他测试文件中运行良好。

我的控制台中没有任何错误发生的日志输出。

import React from 'react';
import { shallow } from 'enzyme';
import { SomeComponent } from '../SomeComponent';

describe('SomeComponent', () => {
  it('renders', () => {
    const props = { name: 'hey' }
    const shallowWrap = shallow(<SomeComponent {...props} />);
    console.log(shallowWrap) // this wont even log
    expect(shallowWrap).toMatchSnapshot();
  });
});

【问题讨论】:

    标签: javascript react-native jestjs enzyme


    【解决方案1】:
    try {
      const shallowWrap = shallow(<SomeComponent {...props} />);
    } catch (e) {
      console.log(e)
    }
    

    围绕我的组件的浅化包装一个 try/catch 并记录错误表明我在 SomeComponent 的渲染函数中抛出了一个错误。

    修复了导致该错误的原因,现在可以完美运行。

    【讨论】:

      猜你喜欢
      • 2018-10-07
      • 2018-03-10
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多