menu

Testing Library

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

Channels
Team
Posts
Members
Info

How to mock document.createRange(...).createContextualFragment?

Hey, asFragment uses document.createRange and createContextualFragment, if it's available. I'm running my tests with jest@24 and jsdom@14, so I need to mock document.createRange. …

thumbsup
0
message-simple
3

how to apply react testing library

I am applying to react testing library into the code base of the company, but, I not sure understand codebase 100%. Should help me some advice?

thumbsup
0
message-simple
1

React Testing for Hooks

Hello, as am learning to write unit test for React Functional Components in Hooks, finding it difficulty for below tasks. 1. Which library to choose. 2. Seen few blogs that recommend react-testing-library, but doesn't know where to start from. …

thumbsup
0
message-simple
2

How to test if selecting a label causes an input to focus

We want to ensure that our form components labels are focusing inputs when selected. Our test looks like: We've tried a couple variations of https://spectrum.chat/testing-library/general/how-to-test-element-is-focused~abdca784-a6e9-4324-a7af-5432b128baf0 with no success.

thumbsup
0
message-simple
2

How do you get jest-dom working with TypeScript?

I am trying to use jest-dom with TypeScript but it's not recognizing the added methods to the expect(). How do I get this working?

thumbsup
0
message-simple
1

Debug output too long for terminal

I'm unsure this issue is related to testing-library, but every time i write tests i stumble over it - so maybe one of you guys already solved it. Using debug() for a big component (in terms of html lines) only prints a part of the complete component in the terminal. Rest is…

thumbsup
0
message-simple
2

Test that something is not on the page

I have a test similar to this one This works fine. I would like to do the opposite. I want to test non-admin can not open the modal. In this scenario the button is still on the page, it just doesn't open the modal on click. I'm aware I can do expect(queryByText('The modal…

thumbsup
2
message-simple
13

Should getByText use a hard coded string

Should getByText use a hard coded string ,getByText(/some text/), or any reason to not use the same variable that's used in the component? e.g getByText(STRINGS.SOME_TEXT)

thumbsup
0
message-simple
1

Unable to make mocked async calls with axios

Hi All, I was unable to mock async calls with Axios, as shown in this example.https://testing-library.com/docs/react-testing-library/example-intro. Not sure what am I doing wrong here. Able to replicate the same problem in…

thumbsup
0
message-simple
3

Attempting to mock Firebase

Hey all, I want to test a component which calls firebase.auth().signOut() on click, so I want to test that firebase is being called onClick, but am not sure how to implement - I don't want to call the api in a test. Also, I am unsure if this is a valuable test. I would love some…

thumbsup
0
message-simple
27