score:15
you have to stub out window.getselection().removeallranges()
. i think this would work:
before(() => {
window.getselection = () => {
return {
removeallranges: () => {}
};
})
});
score:0
for me, i also need this mock window.document.getselection = jest.fn()
score:7
2020 update
i was struggling with this as well and @mohammad comment pointed me in the right direction, so i decided to add that as an answer here to help others:
as mentioned by @mohammad, jsdom
is now on version 16, which supports getselection
. however, jest@25
is still using older versions of jsdom
, so what you can do is use this npm package to "by pass" that:
https://www.npmjs.com/package/jest-environment-jsdom-sixteen
after the install, just update your jest
config to use this:
{
"testenvironment": "jest-environment-jsdom-sixteen"
}
or, use it as a flag direct in the npm command:
npm run test --env=jsdom-sixteen
Source: stackoverflow.com
Related Query
- Enzyme Jest window.getSelection() does not work
- Using `expect.any(Object)` or `expect.anything()` does not work to match `undefined` in Jest
- Mount does not work in enzyme with next js
- Typescript test with Jest with Enzyme does not recognise components
- "toHaveStyle" does not work on Jest (React Typescript)
- <element>.innerText in component method code does not work properly in enzyme testing. Testing react component with Jest+Enzyme(mount())
- React Enzyme setState does not work when attepting to test with mount
- Enzyme onclick spy toHaveBeenCalled test does not work when testing on arrow function
- Maxlength does not work React Js
- React css transition does not work correctly
- Next.js - import css file does not work
- react-router does not work in production and surge deployments
- Pressing enter to submit form in react-testing-library does not work
- onClick does not work for custom component
- Apollo Optimistic UI does not work in Mutation Component?
- Windows 10 -> 'npx create-react-app myapp' command does not work because of whitespace username in file path
- WebStorm auto completion does not work for React js
- CodeMirror does not work with React/Webpack
- Webpack 4 devtool option does not work with webpack-dev-server
- React. preventDefault() for onCopy event does not work
- Material UI component reference does not work
- Material Autocomplete does not work with InputProps
- this.setState() does not work in componentWillReceiveProps
- Why does hot reloading not work for reactjs visual studio 2019 template
- this.node.contains does not work if this.node is a ref to react component
- React's TestUtils.Simulate.keyDown does not work
- ComponentDidCatch does not work
- How to test default props functions is attached to component or not ? | React | Jest | Enzyme
- React - zIndex does not work
- React-Select with React-Apollo does not work
More Query from same tag
- Why would we useCallback in useIsMounted hook to return the ref from the hook?
- Nx.dev Gatsby throws error in plugin gatsby-plugin-translate-urls - Support for the experimental syntax 'jsx' isn't
- browserify cannot find module 'react'
- Is there a way to get the React / Redux's bundle.js on the local hard drive?
- Adding Jquery and React fb to html file
- Unexpected end of JSON input error
- HTML Element with React variable does not display ASCII
- How can I use PHP to save the state of a React component in a JSON file?
- Nextjs stuck loading the home page
- Testing image's 'naturalHeight' without DOM
- Reactjs best practice to make a component controllable by other components?
- Redux saga debounce and not just delay/cancel
- The user aborted a request - ReactJS
- Is there a way to create a generic approach to reduce amount of code for similar operations on state?
- iPhone will only focus on one html input text of two on screen?
- What takes place where in reactjs build system?
- React.Children.only expected to receive a single React element child error
- Webpack with Babel gives uncaught referenceError: require is not defined
- Callback function not automatically re-rendering the react component page
- Why document.execCommand not working in reactjs?
- Is there a way to call useContext in a click callback?
- Cannot read property 'tabsDivIframe' of undefined - React
- when route changes in my React app I clearInterval() and app breaks
- Dynamically pass parameter to web service on react js app
- Cannot import anything from bit.dev to my React project
- Onclick component setState() of main component
- How to access cookies correctly in express application
- Children props are not visible in parent component
- How can I give appropriate icons in HTML tag using object values in React?
- How to get ref value of button in function [react]