This repository was archived by the owner on Apr 19, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ const Counter = (props: IProps) => {
1212 return (
1313 < div >
1414 < p > Counter: { counter } </ p >
15- < button onClick = { increment } label = "Increment" />
16- < button onClick = { decrement } label = "Decrement" />
15+ < button onClick = { increment } label = "Increment" id = "increment" />
16+ < button onClick = { decrement } label = "Decrement" id = "decrement" />
1717 </ div >
1818 ) ;
1919} ;
Original file line number Diff line number Diff line change 1+ import * as React from "react" ;
2+ import { shallow } from "enzyme" ;
3+
4+ import Counter from "../Counter" ;
5+
6+ describe ( "counter container" , ( ) => {
7+ let subject : any ,
8+ mockIncrement : ( ) => { } ,
9+ mockDecrement : ( ) => { } ;
10+ beforeEach ( ( ) => {
11+ mockIncrement = jest . fn ( ) ;
12+ mockDecrement = jest . fn ( ) ;
13+ subject = shallow ( < Counter increment = { mockIncrement } decrement = { mockDecrement } counter = { 1 } /> ) ;
14+ } ) ;
15+
16+ it ( "it shows the counter" , ( ) => {
17+ expect ( subject . text ( ) ) . toContain ( "1" ) ;
18+ } ) ;
19+
20+ it ( "clicking on the increment button call property increment" , ( ) => {
21+ subject . find ( "#increment" ) . props ( ) . onClick ( ) ;
22+
23+ expect ( mockIncrement ) . toBeCalled ( ) ;
24+ } ) ;
25+
26+ it ( "clicking on the decrement button call property decrement" , ( ) => {
27+ subject . find ( "#decrement" ) . props ( ) . onClick ( ) ;
28+
29+ expect ( mockDecrement ) . toBeCalled ( ) ;
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments