【发布时间】:2021-07-30 02:54:06
【问题描述】:
这是一个使用mocked function 的简单测试。但我确实收到了模拟调用Object is possibly 'undefined'.ts(2532) 的 ts 错误。我不知道如何摆脱这个错误。 This is the structure 的调用对象,所以我认为我正确处理了它......但显然不是 ts 预期的那样。
import { render, fireEvent } from '@testing-library/react'
const mockSetCheckbox = jest.fn(() => Promise.resolve())
test('should select checkbox', () => {
// ...
userEvent.click(checkbox)
expect(mockSetCheckbox.mock.calls[0][0].variables.input.checkbox).toBe(true)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Object is possibly 'undefined'.ts(2532)
})
【问题讨论】:
标签: javascript typescript unit-testing jestjs