menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Team
Posts
Members
Info

getAllBy...(_) for a nested button on 3rd party library with dropdown

I am trying to test the following scenario: I have a list of "command bar buttons" with the "split" option set to true from this library https://developer.microsoft.com/en-us/fabric#/controls/web/button …

thumbsup
0
message-simple
12

How to ignore some lines in the snapshot comparison?

Hey guys! I'm trying to use snapshots to check there is no change in the visual of my react component. but my component show a text with a date for example: …

thumbsup
0
message-simple
2

Test plain HTML + vanilla JS?

At the moment I want to test a plain HTML page. However, the Javascript is not executing. Perhaps because it is not actually loaded, and I'm just running a query against plain text? How can I create an actual DOM to test against?

thumbsup
0
message-simple
0

getBy queries representing stale values?

This is something I'm not too sure about. I may be performing an "anti-pattern" and would like to confirm with the community. I'm writing a test to change the value of an input and assert that a button is enabled when the input has a value: The above test fails when asserting if…

thumbsup
0
message-simple
1

How to test the code which uses IntersectionObserver API.

So, I was writing one custom hook useInstersectionObserver. What should be the right approach to test this kind of react custom hook. Here is the link to the code: https://codesandbox.io/embed/useintersectionobserver-sbz54 Note: I am new to react testing library, might be…

thumbsup
0
message-simple
1

Fire scroll event with specified X, Y positions

I have a UI that changes if the user has scrolled at least 100 pixels in the Y direction, so I would like to fire an event similar to this: fireEvent.scroll(window, {scrollY: 101}) The event is fired, but the scrollY value does not change. Can anyone help?

thumbsup
0
message-simple
1

Is there any way to trigger document level event listeners

I have some UI that I'm testing that is dependent on document.addEventListener("focusin", ...);. From what I can tell interacting with the UI using DTL api doesn't trigger these events. Is there any way around this issue?

thumbsup
0
message-simple
0

Testing visibility of an element with CSS

I'd like to test if a component is visible using toBeVisible(), but that method doesn't work if CSS is used to show or hide elements: https://github.com/testing-library/jest-dom/issues/116 is there any way to get around this?

thumbsup
0
message-simple
4

Invariant Violation: Too many re-renders

React Hooks. Functional Component. When I use hooks useState to set state I get the above error in my RTL test. This is the relevant code: Any idea why I'm getting this error and how I can fix it? Thx...

thumbsup
0
message-simple
0

How to fire fireEvent.wheel?

I test React Victory Library, and it's feature - zoom. I've tried to fire fireEvent.wheel(getByTestId('tezt'), { deltaY: -120 …

thumbsup
1
message-simple
0