Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
6k views

I'm using react-testing-library within a project of mine and am trying to write tests that validate in-app routing. e.g. testing that a button on the AccessDenied page brings you back to the Home page....
jrnxf's user avatar
  • 1,014
18 votes
5 answers
27k views

I'm trying to understand how to best test that react-router behaves as expected with @testing-library/react. The simplest test I can think of, is to verify that clicking a link changes the URL. I ...
Florian Bienefelt's user avatar
20 votes
3 answers
43k views

I am writing a simple test using react-native-testing-library (my first steps with that library) in my react native expo app. But I am getting a confused error coming from somewhere inside react-...
TheSoul's user avatar
  • 5,386
9 votes
4 answers
42k views

so I am trying to test that the onSubmit function is getting triggered if the button is clicked - the way im doing this is through testing the internals of the onSubmit function is getting calles (...
EliyaMelamed's user avatar
135 votes
4 answers
212k views

Here is my custom hook: export function useClientRect() { const [scrollH, setScrollH] = useState(0); const [clientH, setClientH] = useState(0); const ref = useCallback(node => { ...
Neda Homa's user avatar
  • 4,387
17 votes
1 answer
17k views

I'm trying to test a responsive design where I hide some text (in spans) when the screen size is too narrow. import React from 'react' import './index.css' function Welcome(props) { return ( &...
Norfeldt's user avatar
  • 9,620
9 votes
2 answers
29k views

My component looks something like this: (It has more functionality as well as columns, but I have not included that to make the example simpler) const WeatherReport: FunctionComponent<Props> = ({...
Vishal's user avatar
  • 6,428
0 votes
1 answer
2k views

I'm new on testing and I'm trying to implement a unit test to check if a counter is being correctly updated after a button is clicked. Everything works fine on dev and production environments, so I'm ...
Berg_Durden's user avatar
  • 1,811
92 votes
4 answers
34k views

What is the difference between enzyme, ReactTestUtils and react-testing-library for react testing? The ReactTestUtils documentation says: ReactTestUtils makes it easy to test React components in ...
Black's user avatar
  • 10.5k
75 votes
14 answers
88k views

App.js import React, { Component } from "react"; import Select from "react-select"; const SELECT_OPTIONS = ["FOO", "BAR"].map(e => { return { value: e, label: e }; }); class App extends ...
user2133814's user avatar
  • 2,681
30 votes
1 answer
31k views

I have set up a github project to understand how to better test react (v 16.8.0) useEffect hook. I make an api call to fetch data inside useEffect and I set the received data as state component ...
delca85's user avatar
  • 1,276
24 votes
4 answers
13k views

I am using react-testing-library. In the document it says Note that using this as an escape hatch to query by class or id is a bad practice because users can't see or identify these attributes. ...
klabe's user avatar
  • 525
22 votes
4 answers
17k views

I'm trying to paste text that's already in my clipboard into a textbox, but I dont understand how to use "eventInit" to do this. I've read the documentation on how to paste text into a ...
Noob's user avatar
  • 1,114
15 votes
3 answers
18k views

I'm trying to test my antd application with react testing library, but I keep getting this error: TypeError: Cannot read property 'addListener' of undefined Im using a custom render but the error ...
Demian's user avatar
  • 372
11 votes
1 answer
44k views

I would like to test a small React web app where I use the global fetch method. I tried to mock fetch in this way: global.fetch = jest.spyOn(global, 'fetch').mockImplementation(endpoint => ...
Giorgio's user avatar
  • 2,337
8 votes
1 answer
9k views

I've got a unit test using Jest and React Testing Library that fills and submits a form. The problem is that after upgrading Material UI to version 4 my unit test fails to select an option. The error ...
Viny Machado's user avatar
254 votes
19 answers
299k views

Here is my code for a tooltip that toggles the CSS property display: block on MouseOver and on Mouse Out display: none. it('should show and hide the message using onMouseOver and onMouseOut events ...
dorriz's user avatar
  • 2,769
107 votes
4 answers
228k views

I'm using the getByTestId function in React Testing Library: const button = wrapper.getByTestId("button"); expect(heading.textContent).toBe("something"); Is it possible / ...
Evanss's user avatar
  • 22.5k
94 votes
2 answers
55k views

There are two ways to use queries using React Testing Library. You can either use the queries returned by the render method: import React from 'react' import { render } from '@testing-library/react' ....
Erazihel's user avatar
  • 7,645
94 votes
3 answers
172k views

I need some help understanding how one can test an application using React Context. Here's my sample setup. context.js import React from 'react' export const AppContext = React.createContext() App....
artooras's user avatar
  • 6,905
89 votes
4 answers
107k views

I'd like to test mouse interaction with an element using React Testing Library. Presently it's a bit unclear to me the difference between userEvent.click(element) and fireEvent.click(element). Are ...
user2190690's user avatar
  • 2,104
56 votes
3 answers
153k views

I'm following a tutorial on React testing. The tutorial has a simple component like this, to show how to test asynchronous actions: import React from 'react' const TestAsync = () => { const [...
lomine's user avatar
  • 1,221
47 votes
3 answers
18k views

So, react-testing-library is used for unit/integration testing, and cypress is used for e2e testing. However, both appear to do the same thing: react-testing-library Facilitates mocking Tests as a ...
jack.benson's user avatar
  • 2,373
39 votes
3 answers
83k views

I'm testing my react app with react testing library and jest. And I want to know how to fetch element with 'name' attribute in react-testing-library. For example, in the following page, is it possible ...
Satoru Kikuchi's user avatar
34 votes
5 answers
89k views

I got a custom hook which I want to test. It receives a redux store dispatch function and returns a function. In order to get the result I'm trying to do: const { result } = renderHook(() => { ...
CodeMonkey's user avatar
  • 12.6k

1
2 3 4 5