Questions tagged [jest-dom]
56 questions
0
votes
1 answer
Is there any way to use Jest and jest-dom together without having to transpile?
I want to write a unit test with Jest, with jest-dom as a mock DOM--without having to transpile. I was hoping all I had to do was import the jest-dom package with a CommonJS import. But when I do that, then run my tests (with npm test), it still…

cag8f
- 817
- 1
- 10
- 33
0
votes
1 answer
Can't import @testing-library/jest-dom, expect.extend is not a function
I'm trying to add @testing-library/jest-dom to my project with no luck. It is installed by yarn into my dev dependencies and imported in setupTests.js with:
import '@testing-library/jest-dom';
The test fails with:
Invalid Chai property:…

Hoi Chan
- 3
- 3
0
votes
1 answer
React doesn't rerender on state change while testing
I am testing a react component which has a simple Material-ui switch that updates a boolean field. The component works without any issues when I run the app locally.
In my test, I am mocking the graphql calls via MockedProvider. The mocked provider…

ege
- 812
- 6
- 16
0
votes
1 answer
Jest-dom unable to find module inside of its folder in node_modules
When I add into my test-setup.js import "@testing-library/jest-dom"; Jest throws me this error when I run any test. If I remove the import everything works fine. Tried to add the import directly in test files, without success.
This is how…

woaouh
- 1
- 1
0
votes
2 answers
How to add @testing-library/jest-dom to every testing file in svelte?
I am trying to add the jest-dom library to every test file.
I installed that package and made the "jestSetup.js" file and add the package.json as below.
"jest":{
setupFilesAfterEnv:["/jestSetup.js"]
}
and jestSetup.js is
import…

mingxingwang
- 169
- 4
- 17
0
votes
1 answer
How to use jest-dom without Jest
I have a question about extending Typescript interfaces.
Here is my situation:
I am using expect in my tests without Jest (I installed it separately and it works).
Now I want to use jest-dom to add the expect matchers for DOM. (they are super…

webNeat
- 2,768
- 1
- 20
- 22
0
votes
0 answers
Enable/disable submit button base on useState boolean values changes true/false using react jest testing library
I am populating the form fields from a configuration and after user updates the fields, I compare the updated fields with configuration fetched earlier using "isEqual". If "isEqual = false" I enable the submit button. I am having little trouble to…

Alwaysalearner
- 85
- 1
- 1
- 10
0
votes
1 answer
Dom Manipulation (AppendChild) fails in Jest
I need some help in below test case : appenChild failing in Jest
updatePopupContent(data) {
const sectionFragment = new DocumentFragment();
//create section return HTML element as per data passed
data.costSection &&…

Bhupendra
- 1,196
- 16
- 39
0
votes
0 answers
React testing library: test failed style (Select + Form Control from MUI)
The problem
I'm trying to test the border is red if the component is in error state, but it's failing in local machine, but not in codesandbox
What I have tried:
Check whether there is a difference between FormHelperText and fieldSet in…

Orville
- 518
- 7
- 17
0
votes
1 answer
expect(...).toHaveAttribute is not a function despite properly extending it
I have my test setup using jest and detox (@e2e)
Issue is, despite seemingly properly importing @testing-lib/jest-dom, I can't seem to use the toHaveAttribute() matcher as I should be able to.
Inside my spec.js file:
import { toHaveAttribute } from…

Samuel Hulla
- 6,617
- 7
- 36
- 70
-1
votes
1 answer
Jest's `it.each` causes a 'Expected done to be called once, but it was called multiple times' error when used with 'getByTestId'
I have a component with some parts that are conditionally rendered based on some config on the window object. This all works, I can confirm this manually.
I have this sort of test setup, but I have simplified it somewhat:
it('renders both by…

AncientSwordRage
- 7,086
- 19
- 90
- 173