File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -18,19 +18,39 @@ const tempArr = [{
1818 onlineStatus : true
1919} ] ;
2020
21+ const initialState = {
22+ hideBtn : false
23+ } ;
24+
2125class App extends Component {
2226
2327 constructor ( props ) {
2428 super ( props ) ;
29+ this . state = {
30+ ...initialState
31+ }
2532 this . fetch = this . fetch . bind ( this ) ;
2633 }
2734
2835 fetch ( ) {
2936 this . props . fetchPosts ( ) ;
37+ this . exampleMethod_updatesState ( ) ;
38+ }
39+
40+ exampleMethod_updatesState ( ) {
41+ const { hideBtn } = this . state ;
42+ this . setState ( {
43+ hideBtn : ! hideBtn
44+ } ) ;
45+ }
46+
47+ exampleMethod_returnsAValue ( number ) {
48+ return number + 1 ;
3049 }
3150
3251 render ( ) {
3352 const { posts } = this . props ;
53+ const { hideBtn } = this . state ;
3454
3555 const configButton = {
3656 buttonText : 'Get posts' ,
@@ -42,7 +62,11 @@ class App extends Component {
4262 < Header />
4363 < section className = "main" >
4464 < Headline header = "Posts" desc = "Click the button to render posts!" tempArr = { tempArr } />
45- < SharedButton { ...configButton } />
65+
66+ { ! hideBtn &&
67+ < SharedButton { ...configButton } />
68+ }
69+
4670 { posts . length > 0 &&
4771 < div >
4872 { posts . map ( ( post , index ) => {
Original file line number Diff line number Diff line change @@ -33,5 +33,18 @@ describe('App Component', () => {
3333 expect ( component . length ) . toBe ( 1 ) ;
3434 } ) ;
3535
36+ it ( 'exampleMethod_updatesState Method should update state as expected' , ( ) => {
37+ const classInstance = wrapper . instance ( ) ;
38+ classInstance . exampleMethod_updatesState ( ) ;
39+ const newState = classInstance . state . hideBtn ;
40+ expect ( newState ) . toBe ( true ) ;
41+ } ) ;
42+
43+ it ( 'exampleMethod_returnsAValue Method should return value as expected' , ( ) => {
44+ const classInstance = wrapper . instance ( ) ;
45+ const newValue = classInstance . exampleMethod_returnsAValue ( 6 ) ;
46+ expect ( newValue ) . toBe ( 7 ) ;
47+ } ) ;
48+
3649
3750} ) ;
You can’t perform that action at this time.
0 commit comments