小编Whj*_*Whj的帖子

JSX元素类型'Element []'不是JSX元素的构造函数吗?

“ @ types / react”:“ ^ 16.7.17”
“ @ types / react-dom”:“ ^ 16.0.11”
“ typescript ”:“ ^ 3.2.2”

function ArryElement() {
  return [
    <div key='1'>1</div>,
    <div key='2'>2</div>
  ];
}

function App() {
  return <ArryElement />
}
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

12
推荐指数
1
解决办法
6070
查看次数

在异步componentDidMount时使用React的Jest和Enzyme进行测试

  • 反应:16.3.0-alpha.1
  • 开玩笑:"22.3.0"
  • 酶:3.3.0
  • 打字稿:2.7.1

码:

class Foo extends React.PureComponent<undefined,undefined>{
   bar:number;
   async componentDidMount() {
     this.bar = 0;
     let echarts = await import('echarts'); // async import
     this.bar = 100;
   }
}
Run Code Online (Sandbox Code Playgroud)

测试:

describe('...', () => {
  test('...', async () => {
    const wrapper = shallow(<Foo/>);
    const instance = await wrapper.instance();
    expect(instance.bar).toBe(100);
  });
});
Run Code Online (Sandbox Code Playgroud)

错误:

Expected value to be:
  100
Received:
  0
Run Code Online (Sandbox Code Playgroud)

typescript reactjs jestjs enzyme

11
推荐指数
2
解决办法
8901
查看次数

标签 统计

reactjs ×2

typescript ×2

enzyme ×1

jestjs ×1