Questions about testing JavaScript code with the Testing Library utilities
Questions tagged [testing-library]
282 questions
0
votes
1 answer
Node Environment variable ignored by testing library
I'm implementing Testing Library with Puppeteer and I was trying to use an environment variable, DEBUG_PRINT_LIMIT, to limit the length of the HTML printed to console in case of failure.
But for some reasons, the variable environment is just ignored…

Timothé Malahieude
- 675
- 6
- 18
0
votes
1 answer
How testing svelte components
There is a component that uses a third-party module
We need to test it, it is desirable not to make a mock component that is imported into it.
Wrote on this example
// test.spec.ts
import Component from "Component";
describe('Component', () => {
…
0
votes
1 answer
react-native-testing-library how to getByText when using react-intl FromattedMessage?
getByText method by react-native-testing-library doesn't seem to find text when it's inside react-intl's
const messages = {
SOME_KEY: 'some key'
}
const { getByText } = render(

Nir Ben-Yair
- 1,566
- 3
- 14
- 18
0
votes
1 answer
How to test a functional component that has a fragment?
How to test a functional component that is using a fragment and props, but is not using markup, I cannot set a role.
const Item = (props: ItemProps) => (
{ props.content }
);

Tabares
- 4,083
- 5
- 40
- 47
0
votes
2 answers
Test cleave.js component with testing-library
I am trying to test a component with testing-library. The problem I'm facing is how to introduce text automatically in an input. Usually this could be achieved by:
const inputName =…

Andrés
- 719
- 1
- 4
- 21
0
votes
1 answer
How do I ensure that an element is not deleted after request fails using testing-library
In my Svelte application I'm trying to test using svelte-testing-library that an element is deleted when a specific API request (using msw) succeeds, but not when it returns an error.
Checking the happy path is easy using
const el = await…

Oskar Persson
- 6,605
- 15
- 63
- 124
0
votes
2 answers
Is it okay to use the expect inside of a waitFor as my "Assert" in Act-Arrange-Assert?
I've recently begun utilizing React / DOM Testing Library in order to test all of my front-end React code. One of the first issues I've encountered is that with the way our application is laid out, I have no way of telling when loading of data…

cjones26
- 3,459
- 1
- 34
- 51
0
votes
1 answer
Using Testing Library in standalone
I was trying to do something similar to the Testing Playground but I don't know which JavaScript file to include to have access to all the Testing Library native functions.
The goal is to be able to run queries like getAllByRole in the browser…

Luís Soares
- 5,726
- 4
- 39
- 66
0
votes
2 answers
Testing Library findBy* queries only working with async/await
From the documentation, findBy queries return a Promise. But it seems like using these queries with Promise.prototype.catch() doesn't work in cases where using them with async/await + try...catch does.
For example, 'not found' gets logged here as…

apikosir
- 35
- 2
- 5
0
votes
1 answer
Testing Library (VueJS) - Rendering multiple components in a it block
Relatively new to testing so this is probably super simple:
I want to test a checkbox component. I got the basics down, however, how can I render multiple components inside an it block?
My code so far. I am stuck on the second test, where I want to…

Riza Khan
- 2,712
- 4
- 18
- 42
0
votes
0 answers
getByRole in Nightwatch Testing Library throws error in basic example
I keep getting an error when running a basic sample with Nightwatch.js + Testing Library:
[Ecosia Search With TL] Test Suite
==================================
ℹ Connected to localhost on port 9515 (1077ms).
Using: chrome (87.0.4280.66) on Mac OS…

Luís Soares
- 5,726
- 4
- 39
- 66
0
votes
1 answer
How to combine configuration of enzyme and react-testing-library in setup.test.js
Our project has both enzyme and testing-library.
My goal is to overwrite getByTestId to my custom.
But when I'm adding the second configuration to my setup.test.js - some tests become failing with Found multiple elements with the…

Dima Dorogonov
- 2,297
- 1
- 20
- 23
0
votes
1 answer
fireEvent doesn't click button on React component
I'm writing tests for a React component. It's a timer that starts counting down when you press a button, then stops when you press the same button. I have a test case that tries to press the pause button, wait a second, then press the pause button…

paul
- 77
- 1
- 10
0
votes
1 answer
fireEvent.change() does not input value
I have a very simple form which has 1 input and currently doing testing on it. However, I can unable to fireEvent.change() to add the input.
Main Code
function Submission(){
// I understand that I can just simply do [name, setName] but in the…

MongChangHsi
- 103
- 1
- 12
0
votes
0 answers
isVisible doesn't work in Jest test using jest-dom
I've created as simplified a CodeSandbox as I can to reproduce my issue. You can see the failing test running in the CodeSandbox.
In my example I have a component called MyCheckbox which is just a wrapper around a material-ui Checkbox. It takes a…

Simon Long
- 1,310
- 4
- 20
- 39