Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Options
3.
computedStyleSupportsPseudoElements
3.1.
defaultHidden
3.2.
showOriginalStackTrace
3.3.
throwSuggestions 
3.4.
testIdAttribute
3.5.
getElementError
3.6.
asyncUtilTimeout
4.
FAQs
5.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Configuration Options

Author Parth Jain
0 upvote

Introduction

The testing library can be configured using the configure function.
The configure function accepts a plain JavaScript object that will be merged into the existing configuration. A function will be provided with the current configuration and return a plain JavaScript object. This blog will help you understand the configure function and its various options.

Options

computedStyleSupportsPseudoElements

It is set as true in the case window.getComputedStyle supports a second argument. Old browser such as Internet Explorer 8 or earlier versions doesn't support this property. However, currently, the jsdom does not support the second argument. This includes versions of jsdom prior to version 16.4.0.

defaultHidden

It has a default value of false. It is the default value of the getByRole hidden option.

showOriginalStackTrace

The waitFor ensures that the stack trace for errors thrown by the Testing Library is shortened so that it becomes easier for the developer to identify the part of code that resulted in the error. To disable this the setshowOriginalStackTrace is set to false. 

throwSuggestions 

Default value false. When throwSuggestions is set to true, it will fail a test that has better query availability and will provide a suggested query instead. 
{suggest:false} can be added as an option to avoid suggestions for a single query.

screen.getByTestId('foo', {suggest: false})

testIdAttribute

Defaults to data-testid.This attribute is used by the getByTestId and related queries.

getElementError

This function returns the error used when a get or find query fails. It takes the error message and container object as arguments.

asyncUtilTimeout

Defaults to 1000ms.This global timeout value in milliseconds is required by waitFor utilities. 

FAQs

  1. What is a testing library?
    The Testing Library family of libraries is a very lightweight solution for testing without all the implementation details. The principal utilities it provides involve querying for nodes similarly to how users would find them. In this way, the testing library helps ensure your tests give you confidence in your UI code.
  2. What is throwSuggestions option in Configuration Options?
    Default value false. When throwSuggestions is set to true, it will fail a test that has better query availability and will provide a suggested query instead.
  3. Who created the testing library?
    Testing Library was developed by Kent C. Dodds, a React educator and an open-source developer. 
  4. What is getElementError option in Configuration Options?
    This function returns the error used when a get or find query fails. It takes the error message and container object as arguments.
  5. What is the asyncUtilTimeout option in Configuration Options?
    Defaults to 1000ms.This option is a global timeout value in milliseconds is required by waitFor utilities. 

Key Takeaways

In this article, we have extensively discussed the Configuration Options in Testing Library.If you are Preparing for interview and don't know where to start, we have got you covered, check out our expert curated courses on our website, You can also check out Coding Ninjas Studio to practice frequently asked interview problems. We hope that this blog has helped you enhance your knowledge regarding Configuration Options and if you would like to learn more, check out our articles. Do upvote our blog to help other ninjas grow. Happy Coding!”

Live masterclass