11import { ReactWrapper } from "enzyme" ;
2- import * as React from "react" ;
3- import { DeepPartial , Middleware } from "redux" ;
42
53import * as actions from "../test/actions" ;
64import { ConnectedDummy } from "../test/Dummy" ;
7- import { createStore , TStoreState } from "../test/store" ;
8- import WrapperWithRedux from "./WrapperWithRedux" ;
9-
10- class Wrapper <
11- C extends React . ComponentType < any > ,
12- S extends { } = TStoreState ,
13- P extends React . ComponentProps < C > = React . ComponentProps < C >
14- > extends WrapperWithRedux < C , S , P > {
15- protected createStore (
16- initialState : DeepPartial < S > ,
17- middlewares : Middleware [ ]
18- ) {
19- return createStore ( initialState , middlewares ) ;
5+ import Wrapper from "../test/TestWrapperWithRedux" ;
6+
7+ const initialState = {
8+ test : {
9+ value : "Default value"
2010 }
21- }
11+ } ;
12+
13+ const component = new Wrapper ( ConnectedDummy ) . withDefaultReduxState (
14+ initialState
15+ ) ;
2216
2317describe ( "WrapperWithRedux" , ( ) => {
2418 describe ( "when using the different render methods" , ( ) => {
25- const component = new Wrapper ( ConnectedDummy ) . withDefaultReduxState ( {
26- test : {
27- value : "Default value"
28- }
29- } ) ;
30-
3119 describe ( "when using 'shallow'" , ( ) => {
3220 it ( "throws an error" , ( ) => {
3321 expect ( ( ) => component . shallow ( ) ) . toThrowError ( ) ;
@@ -58,12 +46,6 @@ describe("WrapperWithRedux", () => {
5846 } ) ;
5947
6048 describe ( "when using the reduxState API" , ( ) => {
61- const component = new Wrapper ( ConnectedDummy ) . withDefaultReduxState ( {
62- test : {
63- value : "Default value"
64- }
65- } ) ;
66-
6749 it ( "mounts with default reduxState correctly" , ( ) => {
6850 const wrapper = component . mount ( ) ;
6951
@@ -90,13 +72,16 @@ describe("WrapperWithRedux", () => {
9072 } ) ;
9173
9274 describe ( "when using the reduxHistory API" , ( ) => {
93- const component = new Wrapper ( ConnectedDummy ) ;
9475 const wrapper = component . mount ( ) ;
9576
9677 it ( "starts with an empty history" , ( ) => {
9778 expect ( component . reduxHistory ) . toEqual ( [ ] ) ;
9879 } ) ;
9980
81+ it ( "renders the correct value" , ( ) => {
82+ expect ( wrapper . find ( ".Dummy--value" ) . text ( ) ) . toBe ( "Default value" ) ;
83+ } ) ;
84+
10085 it ( "clicks the button" , ( ) => {
10186 wrapper . find ( ".Dummy--button" ) . simulate ( "click" ) ;
10287 } ) ;
@@ -110,6 +95,10 @@ describe("WrapperWithRedux", () => {
11095 expect ( matchingActions [ 0 ] . payload ) . toBe ( "Click" ) ;
11196 } ) ;
11297
98+ it ( "renders the correct value" , ( ) => {
99+ expect ( wrapper . find ( ".Dummy--value" ) . text ( ) ) . toBe ( "Click" ) ;
100+ } ) ;
101+
113102 it ( "clicks the button again" , ( ) => {
114103 wrapper . find ( ".Dummy--button" ) . simulate ( "click" ) ;
115104 } ) ;
@@ -156,27 +145,19 @@ describe("WrapperWithRedux", () => {
156145 describe ( "when accessing the store" , ( ) => {
157146 let wrapper : ReactWrapper < typeof ConnectedDummy > ;
158147 const payload = "Dispatched value" ;
159- const state = {
160- test : {
161- value : "Default value"
162- }
163- } ;
164- const component = new Wrapper ( ConnectedDummy ) . withDefaultReduxState ( state ) ;
165-
166- it ( "doesn't have the store defined before mounting" , ( ) => {
167- expect ( component . store ) . toBeUndefined ( ) ;
168- } ) ;
169148
170149 it ( "mounts the component" , ( ) => {
171150 wrapper = component . mount ( ) ;
172151 } ) ;
173152
174- it ( "has the store defined after mounting " , ( ) => {
175- expect ( component . store ) . toBeDefined ( ) ;
153+ it ( "has the expected state in the store " , ( ) => {
154+ expect ( component . store ?. getState ( ) ) . toEqual ( initialState ) ;
176155 } ) ;
177156
178- it ( "has the expected state in the store" , ( ) => {
179- expect ( component . store ?. getState ( ) ) . toEqual ( state ) ;
157+ it ( "renders the default value" , ( ) => {
158+ expect ( wrapper . find ( ".Dummy--value" ) . text ( ) ) . toBe (
159+ initialState . test . value
160+ ) ;
180161 } ) ;
181162
182163 it ( "dispatches an action" , ( ) => {
@@ -198,12 +179,7 @@ describe("WrapperWithRedux", () => {
198179 } ) ;
199180
200181 it ( "renders the new value" , ( ) => {
201- expect (
202- wrapper
203- . update ( )
204- . find ( ".Dummy--value" )
205- . text ( )
206- ) . toBe ( payload ) ;
182+ expect ( wrapper . find ( ".Dummy--value" ) . text ( ) ) . toBe ( payload ) ;
207183 } ) ;
208184 } ) ;
209185} ) ;
0 commit comments