我如何为玩笑测试模拟传单?
How do I mock leaflet for jest tests?
我在 CRA 项目中使用 L.Icon 中的自定义图标。 运行 开玩笑测试时,它一直说 L 未定义。我将如何模拟传单以避免此错误?
我在 leaflet
本身
的类似问题上找到了这个答案
What I can recommend for testing is the following,
just mock leaflet using this in your test file,
that is rendering the map component:
jest.mock('leaflet')
And then you place this leaflet mock you can
find in react-leaflet into the jest mocks folder
(__mocks__/leaflet.js, download the current file from:
https://github.com/PaulLeCam/react-leaflet/blob/master/__mocks__/leaflet.js)
That should be enough in most cases.
参考:https://github.com/Leaflet/Leaflet/issues/6297#issuecomment-499809735
我在 CRA 项目中使用 L.Icon 中的自定义图标。 运行 开玩笑测试时,它一直说 L 未定义。我将如何模拟传单以避免此错误?
我在 leaflet
本身
What I can recommend for testing is the following,
just mock leaflet using this in your test file,
that is rendering the map component:
jest.mock('leaflet')
And then you place this leaflet mock you can
find in react-leaflet into the jest mocks folder
(__mocks__/leaflet.js, download the current file from:
https://github.com/PaulLeCam/react-leaflet/blob/master/__mocks__/leaflet.js)
That should be enough in most cases.
参考:https://github.com/Leaflet/Leaflet/issues/6297#issuecomment-499809735