@@ -46,51 +46,56 @@ const Counter: React.FC = () => {
4646 ) ;
4747} ;
4848
49+ function readCount ( frame : string ) : number {
50+ const match = frame . match ( / C o u n t : \s * ( \d + ) / ) ;
51+ assert . ok ( match , "count line should exist" ) ;
52+ return Number . parseInt ( match [ 1 ] ! , 10 ) ;
53+ }
54+
4955test ( "counter: renders initial state" , ( ) => {
5056 const { lastFrame } = render ( React . createElement ( Counter ) ) ;
5157 const frame = lastFrame ( ) ;
5258 assert . ok ( frame . includes ( "Counter App" ) , "should show title" ) ;
5359 assert . ok ( frame . includes ( "Count:" ) , "should show count label" ) ;
54- assert . ok ( frame . includes ( "0" ) , "should show initial count 0" ) ;
60+ assert . equal ( readCount ( frame ) , 0 , "should show initial count 0" ) ;
5561} ) ;
5662
5763test ( "counter: up arrow increments" , ( ) => {
5864 const { lastFrame, stdin } = render ( React . createElement ( Counter ) ) ;
5965 stdin . write ( "\u001b[A" ) ; // up arrow
60- const frame = lastFrame ( ) ;
61- assert . ok ( frame . includes ( "1" ) , "count should be 1 after up arrow" ) ;
66+ assert . equal ( readCount ( lastFrame ( ) ) , 1 , "count should be 1 after up arrow" ) ;
6267} ) ;
6368
6469test ( "counter: k key increments" , ( ) => {
6570 const { lastFrame, stdin } = render ( React . createElement ( Counter ) ) ;
6671 stdin . write ( "k" ) ;
67- assert . ok ( lastFrame ( ) . includes ( "1" ) , "count should be 1 after k" ) ;
72+ assert . equal ( readCount ( lastFrame ( ) ) , 1 , "count should be 1 after k" ) ;
6873 stdin . write ( "k" ) ;
69- assert . ok ( lastFrame ( ) . includes ( "2" ) , "count should be 2 after second k" ) ;
74+ assert . equal ( readCount ( lastFrame ( ) ) , 2 , "count should be 2 after second k" ) ;
7075} ) ;
7176
7277test ( "counter: down arrow decrements" , ( ) => {
7378 const { lastFrame, stdin } = render ( React . createElement ( Counter ) ) ;
7479 stdin . write ( "k" ) ; // go to 1
7580 stdin . write ( "k" ) ; // go to 2
7681 stdin . write ( "\u001b[B" ) ; // down arrow → 1
77- assert . ok ( lastFrame ( ) . includes ( "1" ) , "count should be 1 after decrement" ) ;
82+ assert . equal ( readCount ( lastFrame ( ) ) , 1 , "count should be 1 after decrement" ) ;
7883} ) ;
7984
8085test ( "counter: does not go below zero" , ( ) => {
8186 const { lastFrame, stdin } = render ( React . createElement ( Counter ) ) ;
8287 stdin . write ( "\u001b[B" ) ; // down arrow at 0
83- assert . ok ( lastFrame ( ) . includes ( "0" ) , "count should stay at 0" ) ;
88+ assert . equal ( readCount ( lastFrame ( ) ) , 0 , "count should stay at 0" ) ;
8489} ) ;
8590
8691test ( "counter: r resets to zero" , ( ) => {
8792 const { lastFrame, stdin } = render ( React . createElement ( Counter ) ) ;
8893 stdin . write ( "k" ) ;
8994 stdin . write ( "k" ) ;
9095 stdin . write ( "k" ) ;
91- assert . ok ( lastFrame ( ) . includes ( "3" ) , "count should be 3" ) ;
96+ assert . equal ( readCount ( lastFrame ( ) ) , 3 , "count should be 3" ) ;
9297 stdin . write ( "r" ) ;
93- assert . ok ( lastFrame ( ) . includes ( "0" ) , "count should reset to 0" ) ;
98+ assert . equal ( readCount ( lastFrame ( ) ) , 0 , "count should reset to 0" ) ;
9499} ) ;
95100
96101test ( "counter: renders border" , ( ) => {
0 commit comments