@@ -21,15 +21,28 @@ Configuration options:
2121` testIdAttribute ` : The attribute used by [ ` getByTestId ` ] ( api-queries#bytestid )
2222and related queries. Defaults to ` data-testid ` .
2323
24+ ` getElementError ` : A function that returns the error used when
25+ [ ` getBy* ` ] ( api-queries#getby ) or [ ` getAllBy* ` ] ( api-queries#getallby ) fail. Takes
26+ the error message and container object as arguments.
27+
2428<!-- DOCUSAURUS_CODE_TABS-->
2529
2630<!-- Native-->
2731
2832``` js
2933// setup-tests.js
3034import { configure } from ' @testing-library/dom'
31-
32- configure ({testIdAttribute: ' data-my-test-id' })
35+ import serialize from ' my-custom-dom-serializer'
36+
37+ configure ({
38+ testIdAttribute: ' data-my-test-id' ,
39+ getElementError : (message , container ) => {
40+ const customMessage = [message, serialize (container .firstChild )].join (
41+ ' \n\n '
42+ )
43+ return new Error (customMessage)
44+ },
45+ })
3346```
3447
3548<!-- React-->
@@ -38,7 +51,7 @@ configure({testIdAttribute: 'data-my-test-id'})
3851// setup-tests.js
3952import { configure } from ' @testing-library/react'
4053
41- configure ({testIdAttribute: ' data-my-test-id' })
54+ configure ({ testIdAttribute: ' data-my-test-id' })
4255```
4356
4457<!-- Cypress-->
@@ -47,7 +60,7 @@ configure({testIdAttribute: 'data-my-test-id'})
4760// setup-tests.js
4861import { configure } from ' @testing-library/cypress'
4962
50- configure ({testIdAttribute: ' data-my-test-id' })
63+ configure ({ testIdAttribute: ' data-my-test-id' })
5164```
5265
5366<!-- END_DOCUSAURUS_CODE_TABS-->
0 commit comments