【发布时间】:2022-02-21 03:34:08
【问题描述】:
Jest 测试文件:
import { mount, shallow } from 'enzyme'
import Browse from '@pages/Home/Browse/index'
describe('Browse test suite', () => {
it('Browse should render correctly', () => {
const component = shallow(<Browse />)
expect(component).toMatchSnapshot()
})
})
我的组件的一部分:
interface IParamTypes {
nodeId: string
}
const Browse = () => {
const { nodeId } = useParams<IParamTypes>()
.....
}
运行测试用例时出错:
● Browse test suite › Browse should render correctly
TypeError: Cannot read properties of undefined (reading 'match')
13 | }
14 | const Browse = () => {
> 15 | const { nodeId } = useParams<IParamTypes>()
^
【问题讨论】:
标签: reactjs react-hooks jestjs