11import { twd , expect , userEvent , screenDom } from "twd-js" ;
22import { describe , it , beforeEach } from "twd-js/runner" ;
3+ import { queryClient } from "#/query-client" ;
34import todoListMock from "./mocks/todoList.json" ;
45
56describe ( "Todo List Page" , ( ) => {
67 beforeEach ( ( ) => {
78 twd . clearRequestMockRules ( ) ;
9+ queryClient . clear ( ) ;
810 } ) ;
911
1012 it ( "should display the todo list" , async ( ) => {
@@ -17,22 +19,22 @@ describe("Todo List Page", () => {
1719 await twd . visit ( "/todos" ) ;
1820 await twd . waitForRequest ( "getTodoList" ) ;
1921
20- const todo1Title = await screenDom . getByText ( "Learn TWD" ) ;
22+ const todo1Title = await screenDom . findByText ( "Learn TWD" ) ;
2123 twd . should ( todo1Title , "be.visible" ) ;
2224
23- const todo2Title = await screenDom . getByText ( "Build Todo App" ) ;
25+ const todo2Title = await screenDom . findByText ( "Build Todo App" ) ;
2426 twd . should ( todo2Title , "be.visible" ) ;
2527
26- const todo1Description = await screenDom . getByText ( "Understand how to use TWD for testing web applications" ) ;
28+ const todo1Description = await screenDom . findByText ( "Understand how to use TWD for testing web applications" ) ;
2729 twd . should ( todo1Description , "be.visible" ) ;
2830
29- const todo2Description = await screenDom . getByText ( "Create a todo list application to demonstrate TWD features" ) ;
31+ const todo2Description = await screenDom . findByText ( "Create a todo list application to demonstrate TWD features" ) ;
3032 twd . should ( todo2Description , "be.visible" ) ;
3133
32- const todo1Date = await screenDom . getByText ( "Date: 2024-12-20" ) ;
34+ const todo1Date = await screenDom . findByText ( "Date: 2024-12-20" ) ;
3335 twd . should ( todo1Date , "be.visible" ) ;
3436
35- const todo2Date = await screenDom . getByText ( "Date: 2024-12-25" ) ;
37+ const todo2Date = await screenDom . findByText ( "Date: 2024-12-25" ) ;
3638 twd . should ( todo2Date , "be.visible" ) ;
3739 } ) ;
3840
@@ -52,7 +54,7 @@ describe("Todo List Page", () => {
5254 await twd . visit ( "/todos" ) ;
5355 await twd . waitForRequest ( "getTodoList" ) ;
5456
55- const noTodosMessage = await screenDom . getByText ( "No todos yet. Create one above!" ) ;
57+ const noTodosMessage = await screenDom . findByText ( "No todos yet. Create one above!" ) ;
5658 twd . should ( noTodosMessage , "be.visible" ) ;
5759
5860 await twd . mockRequest ( "getTodoList" , {
@@ -64,16 +66,16 @@ describe("Todo List Page", () => {
6466 status : 200 ,
6567 } ) ;
6668
67- const titleInput = await screenDom . getByLabelText ( "Title" ) ;
69+ const titleInput = await screenDom . findByLabelText ( "Title" ) ;
6870 await userEvent . type ( titleInput , "Test Todo" ) ;
6971
70- const descriptionInput = await screenDom . getByLabelText ( "Description" ) ;
72+ const descriptionInput = await screenDom . findByLabelText ( "Description" ) ;
7173 await userEvent . type ( descriptionInput , "Test Description" ) ;
7274
73- const dateInput = await screenDom . getByLabelText ( "Date" ) ;
75+ const dateInput = await screenDom . findByLabelText ( "Date" ) ;
7476 await userEvent . type ( dateInput , "2024-12-20" ) ;
7577
76- const submitButton = await screenDom . getByRole ( "button" , { name : "Create Todo" } ) ;
78+ const submitButton = await screenDom . findByRole ( "button" , { name : "Create Todo" } ) ;
7779 await userEvent . click ( submitButton ) ;
7880
7981 await twd . waitForRequest ( "getTodoList" ) ;
@@ -84,7 +86,7 @@ describe("Todo List Page", () => {
8486 date : "2024-12-20" ,
8587 } ) ;
8688
87- const todoList = await screenDom . getAllByText ( / L e a r n T W D | B u i l d T o d o A p p | T e s t T o d o / ) ;
89+ const todoList = await screenDom . findAllByText ( / L e a r n T W D | B u i l d T o d o A p p | T e s t T o d o / ) ;
8890 expect ( todoList ) . to . have . length ( 1 ) ;
8991 } ) ;
9092
0 commit comments