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