menu

Testing Library

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

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team
Posts
Members
Info

Access elements in shadow root

Hey everyone, I have one question which came up during developing a component lately. Is it somehow possible to access shadow DOM elements with the test lib? Thanks!

thumbsup
0
message-simple
0

toHaveTextContent not exact matching.

toHaveTextContent matches on the content containing a value. I was getting false positives when testing that a value of 100 was passing when tested for a value of 10. I resorted to the following expect(countIndicator.textContent).toBe('10') and was interested to know if this was…

thumbsup
0
message-simple
1

Testing combobox filtering returning no results

Hey all, I am trying to test a combobox library I built, and having some troubles. The library works as i'd expect in the browser, elements are getting filtered and are visible within the dom but when writing tests, i keep getting no results returned. Demo:…

thumbsup
0
message-simple
1

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
5

TypeError: document.createRange is not a function

Hi everyone, After upgrading to latest react-dom and react testing library run into these issues with my tests TypeError: document.createRange is not a function …

thumbsup
0
message-simple
0

Mocking DOM node

Hi guys, I have a component which is using data that is being grabbed by an attribute of a specific DOM node. Do you know how I can mock that DOM node/the attribute of the DOM node? i.e in this example how can I mock the node which has id "region"

thumbsup
0
message-simple
1

Can Testing Library run on a live site?

For reasons that are too long to go into here, I'm not able to build or deploy the code locally but instead I push it to the server. Is it possible to use Testing Library to run tests on a live site? Thanks!

thumbsup
0
message-simple
3

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