Kiz*_*zer 5 javascript typescript reactjs jestjs
我有这个简单的测试文件:
describe('index', () => {
it('should bootstrap the app', async () => {
const root = <div />;
jest.spyOn(ReactDOM, 'render');
...
ReactDOM.render.mockImplementationOnce(() => {} );
...
ReactDOM.render.mockRestore();
} );
} );
Run Code Online (Sandbox Code Playgroud)
我收到以下打字稿错误:"TS2339:属性'mockImplementationOnce'在'Renderer'类型上不存在"
任何人都知道如何使TypeScript识别jest模拟方法?
您可以使用类型断言来提示打字稿render是SpyInstance
const render = ReactDOM.render as any as SpyInstance;
render.mockImplementationOnce(() => { });
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2281 次 |
| 最近记录: |