@@ -21,12 +21,20 @@ describe('Wrapped Main View', ()=> {
21
21
store . getState . restore ( ) ;
22
22
store . dispatch . restore ( ) ;
23
23
} ) ;
24
+
24
25
it ( 'It translates correct store state to properties' , ( ) => {
25
26
expect ( main . prop ( 'text' ) ) . to . eql ( stateText ) ;
26
27
} ) ;
27
28
28
- it ( 'It provides onClick property which dispatches change text action' , ( ) => {
29
- main . prop ( 'onClick' ) ( ) ;
29
+ it ( 'It provides changeText property which dispatches change text action' , ( ) => {
30
+ var changeTextFunc = main . prop ( 'changeText' ) ;
31
+
32
+ changeTextFunc ( 'Greetings' ) ;
33
+ var dispatch = store . dispatch . lastCall . args [ 0 ] ;
34
+ expect ( dispatch . type ) . to . equal ( ActionTypes . CHANGE_TEXT ) ;
35
+ expect ( dispatch . text ) . to . equal ( 'Greetings' ) ;
36
+
37
+ changeTextFunc ( 'Hello Text' ) ;
30
38
var dispatch = store . dispatch . lastCall . args [ 0 ] ;
31
39
expect ( dispatch . type ) . to . equal ( ActionTypes . CHANGE_TEXT ) ;
32
40
expect ( dispatch . text ) . to . equal ( 'Hello Text' ) ;
@@ -41,7 +49,7 @@ describe('Main View', function () {
41
49
42
50
before ( ( ) => {
43
51
textValue = 'here is the text' ;
44
- main = mount ( < Main text = { textValue } /> ) ;
52
+ main = mount ( < Main text = { textValue } changeText = { ( ) => { } } /> ) ;
45
53
} ) ;
46
54
47
55
it ( 'Has a view with some text' , ( ) => {
@@ -59,13 +67,26 @@ describe('Main View', function () {
59
67
} ) ;
60
68
61
69
describe ( 'Interaction' , ( ) => {
62
- it ( 'Fires on click property on button press' , ( ) => {
63
- var onClick = sinon . spy ( ) ;
64
- var main = mount ( < Main onClick = { onClick } /> ) ;
70
+ it ( 'Fires on click property on button press sends Hello React to changeText method' , ( ) => {
71
+ var changeTextSpy = sinon . spy ( ) ;
72
+ var text = '' ;
73
+ var main = mount ( < Main text = { text } changeText = { changeTextSpy } /> ) ;
74
+ var button = main . find ( TouchableHighlight ) ;
75
+
76
+ button . prop ( 'onPress' ) ( ) ;
77
+ expect ( changeTextSpy . called ) . to . equal ( true ) ;
78
+ expect ( changeTextSpy . lastCall . args ) . to . eql ( [ 'Hello React' ] ) ;
79
+ } ) ;
80
+
81
+ it ( 'Fires on click property on button press sends Goodbye React to changeText method if text prop is Hello React' , ( ) => {
82
+ var changeTextSpy = sinon . spy ( ) ;
83
+ var text = 'Hello React' ;
84
+ var main = mount ( < Main text = { text } changeText = { changeTextSpy } /> ) ;
65
85
var button = main . find ( TouchableHighlight ) ;
66
86
67
87
button . prop ( 'onPress' ) ( ) ;
68
- expect ( onClick . called ) . to . equal ( true ) ;
88
+ expect ( changeTextSpy . called ) . to . equal ( true ) ;
89
+ expect ( changeTextSpy . lastCall . args ) . to . eql ( [ 'Goodbye React' ] ) ;
69
90
} ) ;
70
91
} ) ;
71
92
} ) ;
0 commit comments