58 questions
1
vote
0
answers
146
views
React Testing Library/ Jest Dom (Custom Matcher) not..toBeDisabled() and .toBeEnabled (does not work as expected)
I am new in Jest and React Testing Library and want to test my Form created with Formik and Yup. The test should test when the User inputs invalid values, that the Submit Button should be disabled.
I ...
1
vote
2
answers
978
views
Jest's setupFilesAfterEnv setupFile doesn't get read by VSCode IDE unless it's actually open
I've created a minimal repo where this issue is reproduced. If you have time, try it out: https://github.com/Danielvandervelden/jest-error-minimal-repro
I have not tried any other editor than VSCode
...
2
votes
0
answers
919
views
Echarts problem with vitest and react-testing-libraries
I am using a combination of vitest as test runnert, js-dom as dom matcher and @testing-libraries to create react component unit test.
After change from jest to vitest, I start getting an error on ...
0
votes
1
answer
171
views
The CSS file is not taken into account in the tests of my custom library
I want to test the Hover onto one off my element into my custom lib
but there is an issues when testing if the hover correctly apply my chosen style.
It seems that my css file is not taken when using ...
0
votes
1
answer
1k
views
"Unresolved function or method toHaveValue()" and "Argument types do not match parameters" warnings | WebStorm
I am writing tests for React component with @testing-library/react and vitest. Here is my code:
It works fine, but for some reason I get these annoying warnings:
When I rewrite code to this:
then ...
3
votes
2
answers
4k
views
Trouble testing React component render with Jest and Testing-Library because there's no Document available to Jest
Context/Setup:
I'm trying to use Jest and React-Testing-Library to test the render of a React component <Main/>, but when I run the test, the client that handles fetch throws an error because it'...
1
vote
2
answers
6k
views
Testing the return value from an useMemo with React/Jest
I have a component that converts a person's name to two initials with a useMemo.
I simply want to test the content to be "SB" when the name is Sjaak de Boer. But the useMemo (or if I simple ...
2
votes
1
answer
746
views
The fireEvent.click() from @testing-library/angular not working for 'ion-button' component but works for normal button
I am developing an application with Ionic Angular. While I am testing with @testing-library/angular, the test is not working for ion-button but works for normal button field. What could be the problem?...
3
votes
2
answers
2k
views
Mock animate function in react-testing-library / jest
I am using animate function to animate height of a div. The code looks like this and happens in useLayoutEffect :
const animation = ref.current.animate(
{ height: [oldHeight, newHeight] }...
-1
votes
1
answer
2k
views
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 ...
5
votes
1
answer
8k
views
Testing with 'toHaveStyle' passes when expecting fail
I'm learning about testing and react. I'm having a little trouble understanding why a test is passing when it should not:
From App.js
<button style={{backgroundColor: 'gray'}}>
...
0
votes
1
answer
52
views
How do I test an inner function that is been looped over with jest
How do you test an inner function that is been looped over in jest?
Example I have:
index.js
const innerFunc = (type) => document.querySelector(`input[name="${type}"]`).value;
const ...
2
votes
0
answers
878
views
How do I test react-select value with react-testing-library?
I am using the latest react-select (https://react-select.com/home) and react-testing-library (https://testing-library.com/docs/react-testing-library/intro/) with jest-dom (https://github.com/testing-...
2
votes
1
answer
7k
views
Property 'toBeInTheDocument' does not exist on type 'Matchers<void, HTMLElement>'
Having problems setting up ts-jest with jest-dom and react-testing library in a Next JS app, it seems I am unable to get access to any of the @testing-library/jest-dom matchers.
Anyone have any ...
0
votes
1
answer
4k
views
Can't test the input checkbox properly when the element is disabled using @testing-library/vue
I'm trying to create some tests for a checkbox component but looks like I can't make an assertion for an input[type="checkbox"] when is disabled.
In the first two blocks I'm testing if the ...
1
vote
1
answer
3k
views
toHaveValue returns null while the input's value is 0
I'm working on a test code for my React project. What I want to check is 'if the input type is number, it disallow the text insertion'. Below is the test code I wrote.
it("disallow a text input&...
0
votes
1
answer
3k
views
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 ...
0
votes
1
answer
3k
views
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 ...
7
votes
2
answers
3k
views
Making assertions with mocha and chai when using react-testing-library? [closed]
I would like to add React Testing Library to a project that uses mocha and chai for unit tests. I am a bit stumped when it comes to writing assertions, most examples make use of jest and jest-dom. I ...
2
votes
0
answers
901
views
TypeError: element.getRootNode is not a function while testing
I am using react-testing-library with jest-dom. It is working fine but when i try to use toBeInTheDocument it throws the error TypeError: element.getRootNode is not a function.
expect(getByText('Not ...
6
votes
4
answers
3k
views
React Testing Library - "messageParent" can only be used inside a worker
I'm testinng a react component using the RTL, and everytime I ran a test, I get,
"messageParent" can only be used inside a worker
**Here's the code
describe('Header', () => {
it('...
27
votes
3
answers
76k
views
Why do I get the error "Received value must be an HTMLElement or an SVGElement" when using react-native?
I'm new to unit testing and I'm trying to render a component to learn more about the library.
I'm trying to follow this guide.
Component
<TouchableOpacity
style={style}
onPress={onPress}
...
0
votes
1
answer
412
views
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 ...
1
vote
2
answers
1k
views
Using jest-dom in StencilJS tests throws error
I have a unit test in StencilJS in which I am using a jest matcher from jest-dom. When I run the test it throws an error:
TypeError: Right-hand side of 'instanceof' is not an object
at ...
0
votes
1
answer
1k
views
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 ...