Reputation: 1101
When trying to use ezymes mount
on a component that is rendering MaterialUI's Tooltip, there is an error stopping my tests:
TypeError: document.createRange is not a function
Upvotes: 4
Views: 4460
Reputation: 199
For anyone looking Typescript solution
document.createRange = () => ({
setStart: jest.fn(),
setEnd: jest.fn(),
// @ts-ignore
commonAncestorContainer: {
nodeName: 'BODY',
ownerDocument: document,
},
})
Upvotes: 5
Reputation: 1101
To fix this I defined document.createRange
in my ./src/setupTest.js
document.createRange = () => ({
setStart: () => {},
setEnd: () => {},
commonAncestorContainer: {
nodeName: "BODY",
ownerDocument: document,
},
})
Upvotes: 13