11/* eslint-disable react/no-multi-comp */
2- import React , { Fragment } from 'react' ;
2+
3+ import * as React from 'react' ;
34import ReactDOM from 'react-dom' ;
45import createTheming from '../createTheming' ;
56
@@ -26,8 +27,6 @@ describe('createTheming', () => {
2627 secondaryColor : '#ffffff' ,
2728 } ;
2829
29- const originalTheme = { ...lightTheme } ;
30-
3130 const { ThemeProvider, withTheme, useTheme } = createTheming ( darkTheme ) ;
3231
3332 it ( 'provides theme prop with HOC' , ( ) => {
@@ -115,7 +114,7 @@ describe('createTheming', () => {
115114 ) ;
116115 } ) ;
117116
118- it ( 'allows to use ref on wrapped component' , ( ) => {
117+ it ( 'sets correct ref on wrapped component' , ( ) => {
119118 class Component extends React . Component {
120119 foo ( ) {
121120 return 'bar' ;
@@ -125,12 +124,11 @@ describe('createTheming', () => {
125124 return null ;
126125 }
127126 }
127+
128128 const WithThemeComponent = withTheme ( Component ) ;
129129
130130 class Wrapper extends React . Component {
131131 componentDidMount ( ) {
132- expect ( typeof this . comp ) . toBe ( 'object' ) ;
133- expect ( typeof this . comp . foo ) . toEqual ( 'function' ) ;
134132 expect ( this . comp . foo ( ) ) . toEqual ( 'bar' ) ;
135133 }
136134
@@ -153,71 +151,6 @@ describe('createTheming', () => {
153151 ) ;
154152 } ) ;
155153
156- it ( 'Should set properly getWrappedInstance method' , ( ) => {
157- class Component extends React . Component {
158- foo ( ) {
159- return 'bar' ;
160- }
161-
162- getWrappedInstance ( ) {
163- return this ;
164- }
165-
166- render ( ) {
167- return null ;
168- }
169- }
170- class ComponentWithoutGWI extends React . Component {
171- foo ( ) {
172- return 'bar' ;
173- }
174-
175- render ( ) {
176- return null ;
177- }
178- }
179- const WithThemeComponent = withTheme ( Component ) ;
180- const WithThemeComponentWithoutGWI = withTheme ( ComponentWithoutGWI ) ;
181-
182- class Wrapper extends React . Component {
183- componentDidMount ( ) {
184- expect ( typeof this . comp ) . toBe ( 'object' ) ;
185- expect ( typeof this . comp . getWrappedInstance ) . toEqual ( 'function' ) ;
186- expect ( this . comp . getWrappedInstance ( ) . foo ( ) ) . toEqual ( 'bar' ) ;
187-
188- expect ( typeof this . compWithoutGWI ) . toBe ( 'object' ) ;
189- expect ( typeof this . compWithoutGWI . getWrappedInstance ) . toEqual (
190- 'function'
191- ) ;
192- expect ( this . compWithoutGWI . getWrappedInstance ( ) . foo ( ) ) . toEqual ( 'bar' ) ;
193- }
194-
195- render ( ) {
196- return (
197- < Fragment >
198- < WithThemeComponent
199- ref = { component => {
200- this . comp = component ;
201- } }
202- />
203- < WithThemeComponentWithoutGWI
204- ref = { component => {
205- this . compWithoutGWI = component ;
206- } }
207- />
208- </ Fragment >
209- ) ;
210- }
211- }
212-
213- ReactDOM . render (
214- < ThemeProvider >
215- < Wrapper />
216- </ ThemeProvider > ,
217- node
218- ) ;
219- } ) ;
220-
221154 it ( 'merge theme from provider and prop' , ( ) => {
222155 const PropsChecker = withTheme ( ( { theme } ) => {
223156 expect ( theme ) . not . toBe ( lightTheme ) ;
@@ -290,26 +223,25 @@ describe('createTheming', () => {
290223 } ) ;
291224
292225 it ( 'doesnt mutate existing theme' , ( ) => {
226+ const overrides = { primaryColor : 'red' } ;
293227 const Checker1 = withTheme ( ( { theme } ) => {
294- expect ( theme ) . toEqual ( {
295- ...lightTheme ,
296- primaryColor : 'red' ,
297- } ) ;
228+ expect ( theme ) . not . toBe ( lightTheme ) ;
229+ expect ( theme ) . not . toBe ( overrides ) ;
298230 return null ;
299231 } ) ;
300232
301233 const Checker1WithTheme = withTheme ( Checker1 ) ;
302234
303235 const Checker2 = withTheme ( ( { theme } ) => {
304- expect ( theme ) . toEqual ( originalTheme ) ;
236+ expect ( theme ) . toBe ( lightTheme ) ;
305237 return null ;
306238 } ) ;
307239
308240 const Checker2WithTheme = withTheme ( Checker2 ) ;
309241
310242 ReactDOM . render (
311243 < ThemeProvider theme = { lightTheme } >
312- < Checker1WithTheme theme = { { primaryColor : 'red' } } />
244+ < Checker1WithTheme theme = { overrides } />
313245 < Checker2WithTheme />
314246 </ ThemeProvider > ,
315247 node
0 commit comments