“ @ 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)
码:
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)