1414
1515import re
1616
17+ import pytest
18+
1719from playwright .async_api import Locator , Page , expect
1820
1921
@@ -33,7 +35,7 @@ def _unshift(snapshot: str) -> str:
3335
3436async def check_and_match_snapshot (locator : Locator , snapshot : str ) -> None :
3537 assert await locator .aria_snapshot () == _unshift (snapshot )
36- await expect (locator ).to_match_aria_snapshot (snapshot )
38+ await expect (locator ).to_match_aria_snapshot (snapshot , timeout = 1000 )
3739
3840
3941async def test_should_snapshot (page : Page ) -> None :
@@ -103,3 +105,113 @@ async def test_should_snapshot_with_ref(page: Page) -> None:
103105 - /url: about:blank
104106 """
105107 assert await page .locator ("body" ).aria_snapshot (ref = True ) == _unshift (expected )
108+
109+
110+ async def test_should_snapshot_with_unexpected_children_equal (page : Page ) -> None :
111+ await page .set_content (
112+ """
113+ <ul>
114+ <li>One</li>
115+ <li>Two</li>
116+ <li>Three</li>
117+ </ul>
118+ """
119+ )
120+ await expect (page .locator ("body" )).to_match_aria_snapshot (
121+ """
122+ - list:
123+ - listitem: One
124+ - listitem: Three
125+ """ ,
126+ )
127+ with pytest .raises (AssertionError ):
128+ await expect (page .locator ("body" )).to_match_aria_snapshot (
129+ """
130+ - list:
131+ - /children: equal
132+ - listitem: One
133+ - listitem: Three
134+ """ ,
135+ timeout = 1000 ,
136+ )
137+
138+
139+ async def test_should_snapshot_with_unexpected_children_deep_equal (page : Page ) -> None :
140+ await page .set_content (
141+ """
142+ <ul>
143+ <li>
144+ <ul>
145+ <li>1.1</li>
146+ <li>1.2</li>
147+ </ul>
148+ </li>
149+ </ul>
150+ """
151+ )
152+ await expect (page .locator ("body" )).to_match_aria_snapshot (
153+ """
154+ - list:
155+ - listitem:
156+ - list:
157+ - listitem: 1.1
158+ """ ,
159+ )
160+ await expect (page .locator ("body" )).to_match_aria_snapshot (
161+ """
162+ - list:
163+ - /children: equal
164+ - listitem:
165+ - list:
166+ - listitem: 1.1
167+ """ ,
168+ )
169+ with pytest .raises (AssertionError ):
170+ await expect (page .locator ("body" )).to_match_aria_snapshot (
171+ """
172+ - list:
173+ - /children: deep-equal
174+ - listitem:
175+ - list:
176+ - listitem: 1.1
177+ """ ,
178+ timeout = 1000 ,
179+ )
180+
181+
182+ async def test_should_snapshot_with_restored_contain_mode_inside_deep_equal (
183+ page : Page ,
184+ ) -> None :
185+ await page .set_content (
186+ """
187+ <ul>
188+ <li>
189+ <ul>
190+ <li>1.1</li>
191+ <li>1.2</li>
192+ </ul>
193+ </li>
194+ </ul>
195+ """
196+ )
197+ with pytest .raises (AssertionError ):
198+ await expect (page .locator ("body" )).to_match_aria_snapshot (
199+ """
200+ - list:
201+ - /children: deep-equal
202+ - listitem:
203+ - list:
204+ - listitem: 1.1
205+ """ ,
206+ timeout = 1000 ,
207+ )
208+ await expect (page .locator ("body" )).to_match_aria_snapshot (
209+ """
210+ - list:
211+ - /children: deep-equal
212+ - listitem:
213+ - list:
214+ - /children: contain
215+ - listitem: 1.1
216+ """ ,
217+ )
0 commit comments