@@ -8,7 +8,12 @@ import {
88 Ivya ,
99 asLocator ,
1010} from '../src'
11- import { expect , test } from 'vitest'
11+ import { beforeEach , expect , test } from 'vitest'
12+
13+ beforeEach ( ( ) => {
14+ // the default
15+ Ivya . options . exact = false
16+ } )
1217
1318test ( 'works correctly' , ( ) => {
1419 const button = document . createElement ( 'button' )
@@ -48,6 +53,64 @@ test('file input', () => {
4853 )
4954} )
5055
56+ test ( 'asLocator generates "exact" correctly dependning on the default' , ( ) => {
57+ Ivya . options . exact = false
58+
59+ expect ( asLocator ( 'javascript' , getByTextSelector ( 'Hello' ) ) ) . toMatchInlineSnapshot (
60+ `"getByText('Hello')"`
61+ )
62+ expect (
63+ asLocator ( 'javascript' , getByTextSelector ( 'Hello' , { exact : true } ) )
64+ ) . toMatchInlineSnapshot ( `"getByText('Hello', { exact: true })"` )
65+ expect (
66+ asLocator ( 'javascript' , getByTextSelector ( 'Hello' , { exact : false } ) )
67+ ) . toMatchInlineSnapshot ( `"getByText('Hello')"` )
68+
69+ expect (
70+ asLocator ( 'javascript' , getByRoleSelector ( 'alert' , { name : 'Hello' } ) )
71+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello' })"` )
72+ expect (
73+ asLocator (
74+ 'javascript' ,
75+ getByRoleSelector ( 'alert' , { name : 'Hello' , exact : true } )
76+ )
77+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello', exact: true })"` )
78+ expect (
79+ asLocator (
80+ 'javascript' ,
81+ getByRoleSelector ( 'alert' , { name : 'Hello' , exact : false } )
82+ )
83+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello' })"` )
84+
85+ Ivya . options . exact = true
86+
87+ expect ( asLocator ( 'javascript' , getByTextSelector ( 'Hello' ) ) ) . toMatchInlineSnapshot (
88+ `"getByText('Hello')"`
89+ )
90+ expect (
91+ asLocator ( 'javascript' , getByTextSelector ( 'Hello' , { exact : true } ) )
92+ ) . toMatchInlineSnapshot ( `"getByText('Hello')"` )
93+ expect (
94+ asLocator ( 'javascript' , getByTextSelector ( 'Hello' , { exact : false } ) )
95+ ) . toMatchInlineSnapshot ( `"getByText('Hello', { exact: false })"` )
96+
97+ expect (
98+ asLocator ( 'javascript' , getByRoleSelector ( 'alert' , { name : 'Hello' } ) )
99+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello' })"` )
100+ expect (
101+ asLocator (
102+ 'javascript' ,
103+ getByRoleSelector ( 'alert' , { name : 'Hello' , exact : true } )
104+ )
105+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello' })"` )
106+ expect (
107+ asLocator (
108+ 'javascript' ,
109+ getByRoleSelector ( 'alert' , { name : 'Hello' , exact : false } )
110+ )
111+ ) . toMatchInlineSnapshot ( `"getByRole('alert', { name: 'Hello', exact: false })"` )
112+ } )
113+
51114test ( 'global exact option affects all selector helpers' , ( ) => {
52115 Ivya . options . exact = true
53116
0 commit comments