score:3
turns out that my first answer didn't work for me at the end... i kept running the test and fixing whatever it was complaining about, but there was always something else...
so with some help from a colleague, the solution was to stop react echarts to call echarts by mocking the function triggering the rendering.
let spy: any
beforeall(() => {
spy = jest.spyon(echarts, 'getinstancebydom').mockimplementation(() => {
return {
hideloading: jest.fn(),
setoption: jest.fn(),
showloading: jest.fn()
}
})
})
afterall(() => {
spy.mockrestore()
})
it('renders show correctly', () => {
const tree = renderer
.create(
<show />
)
.tojson()
expect(tree).tomatchsnapshot()
})
in our case we were not interested in actually testing the canvas rendering part, so that worked for us.
score:0
yes, i had to mock the ref object:
function createnodemock(element: any) {
return {
getsomething: jest.fn(() => 'pizza'),
setsomething: jest.fn(),
property: null,
}
}
it('renders show correctly', () => {
const options = { createnodemock }
const tree = renderer
.create(
<show/>,
options
)
.tojson()
expect(tree).tomatchsnapshot()
})
every time i ran into an error running the test, i went to where the method or property was called, console logged, looked what the value was while in the browser and set the data in the mockdata. maybe there is a better way of doing this, but it got it done...
Source: stackoverflow.com
Related Query
- Testing Echarts react component with jest, EchartElement is null
- Testing React Functional Component with Hooks using Jest
- How to mock out sub-components when unit testing a React component with Jest
- Jest testing react component with react-intersection-observer
- JEST + React Testing Library: should I render my component with a beforeAll before tests?
- Testing debounced function in React component with Jest and Enzyme
- Jest snapshot testing React component with randomly generated id (uuid)
- Testing images imported in the component with Jest + React Native
- React testing state of component with Jest and Enzyme
- Testing React component with Jest gives 'Cannot find module' error
- How to replace a React component with a mock when testing with Jest
- Testing React component with Enzyme Jest finding HTML element
- How to use Jest for testing a react component with localStorage?
- Waiting for React component state to update before testing with Jest
- How to mock React Context for testing component with jest
- Testing a React Hooks component with Jest / Enzyme & Axios
- Testing a React component with Jest / Enzyme & Axios
- React component testing with Jest
- Testing render JSON in react component with Jest
- Testing With Jest and Enzyme. Spy On a method of a react component
- Testing component function in React with Enzyme and Jest
- Testing a React Component with Jest
- Testing React Component with Jest and Enzyme. Error: Can't read property of map is undefined
- Testing React Component with Jest Uncovered lines
- Testing React components with Jest & Enzyme: where to test whether component props were given
- React Jest to match snapshot, crash when testing component with child components
- how to test component while passing boolean value with react testing library and jest
- Testing a function in a react component with Jest
- How to test a className with the Jest and React testing library
- How to mock React component methods with jest and enzyme
More Query from same tag
- Why does using React Context with Framer Motion not work?
- Links are display into two rows (React, css)
- Navigate Between Stack Screens using imported button
- i would like to make an individual process in a map function like toggle on click
- onClick() works on the first click only - React
- How to prevent protected route from automatically redirecting on redux state change
- How to implement adding custom js code snippet feature in React SPA?
- How to send firebase refreshToken ? React
- Is "state" a reserved word in React?
- Ract FontAwesome ES6 usage
- Open modal form while retaining a fetch objects properties
- how to use useRef to reference latest value
- Returning html from fetch() and showing in to user
- ./src/routeCollector/Page/MainPage/MainPage.tsx Module not found: Can't resolve './common/HeaderBackground.svg' in
- Accessing redux state when dispatch called in NextJS getInitialProps
- Is there a way to update state without Trigering a re-render?
- Clickable div acting as a button function react js
- How to extract the the alt value form a jsx image element?
- Is there another react form library that maintains full form state on form component unmount/remount?
- __webpack_require__ is not defined. Here map bundle doesn't work
- How can I add style prop as control in Storybook?
- How do I configure a React router to load two components on top of each other (Overlay)?
- Babel react jsx config not works
- Property "value" does not exist on type Readonly
- React - how map an array of objects and add a title without repeating and just showing each unique ttitle
- amcharts Export with Meteor + React (JSX)
- React js does not recognize me map method
- How do I display an image with CSS in ReactJS?
- How to show the correct component according to the user types
- Add opacity in react style backgroundColor using hex values?