玩笑&打字稿-jest.SpyOn类型错误

时间:2020-01-16 10:54:20

标签: reactjs typescript jestjs

我正在尝试使用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
  });

});

0 个答案:

没有答案