我正在尝试使用jest.spyOn
测试在componentDidMount
上调用的方法。我看不到为什么方法onMountFuction
返回Typescript错误:
“ onMountFuction”类型的参数无法分配给的参数 输入
class App extends NextApp<Props> {
componentDidMount() {
this.onMountFuction('The Component Did Mount');
}
onMountFuction(msg: String) {
console.log(msg);
}
render() {
return (
<div></div>
);
}
}
我当前的测试:
describe('Test GTM Intergration', () => {
it('Should Init on ComponentDidMount', () => {
const Props = {
initialState: {},
};
const AppWrapper = new App(Props);
jest.spyOn(AppWrapper, 'onMountFuction'); // Argument of type '"onMountFuction"' is not assignable to parameter of type
});
});