3
3
import { h } from 'preact' ;
4
4
import Template from '../Template' ;
5
5
import { mount , shallow } from 'enzyme' ;
6
+ import { ReactElementLike } from 'prop-types' ;
6
7
7
8
function getProps ( {
8
9
templates = { test : '' } ,
9
10
data = { } ,
10
11
templateKey = 'test' ,
11
12
rootProps = { } ,
12
13
useCustomCompileOptions = { } ,
13
- templatesConfig = { helper : { } , compileOptions : { } } ,
14
+ templatesConfig = { helpers : { } , compileOptions : { } } ,
14
15
...props
15
16
} ) {
16
17
return {
@@ -30,16 +31,16 @@ describe('Template', () => {
30
31
templates : { test : 'it configures compilation <%options%>' } ,
31
32
data : { options : 'delimiters' } ,
32
33
useCustomCompileOptions : { test : true } ,
33
- templatesConfig : { compileOptions : { delimiters : '<% %>' } } ,
34
+ templatesConfig : { helpers : { } , compileOptions : { delimiters : '<% %>' } } ,
34
35
} ) ;
35
- const wrapper = mount ( < Template { ...props } /> ) ;
36
+ const wrapper = mount ( ( < Template { ...props } /> ) as ReactElementLike ) ;
36
37
37
38
expect ( wrapper ) . toMatchSnapshot ( ) ;
38
39
} ) ;
39
40
40
41
it ( 'can configure custom rootTagName' , ( ) => {
41
42
const props = getProps ( { rootTagName : 'span' } ) ;
42
- const wrapper = mount ( < Template { ...props } /> ) ;
43
+ const wrapper = mount ( ( < Template { ...props } /> ) as ReactElementLike ) ;
43
44
44
45
expect ( wrapper ) . toMatchSnapshot ( ) ;
45
46
} ) ;
@@ -50,25 +51,19 @@ describe('Template', () => {
50
51
const props = getProps ( {
51
52
rootProps : { className : 'className' , onClick } ,
52
53
} ) ;
53
- const wrapper = mount ( < Template { ...props } /> ) ;
54
+ const wrapper = mount ( ( < Template { ...props } /> ) as ReactElementLike ) ;
54
55
55
56
expect ( wrapper ) . toMatchSnapshot ( ) ;
56
57
} ) ;
57
58
58
59
describe ( 'shouldComponentUpdate' , ( ) => {
59
- let container ;
60
-
61
- beforeEach ( ( ) => {
62
- container = document . createElement ( 'div' ) ;
63
- } ) ;
64
-
65
60
it ( 'does not call render when no change in data' , ( ) => {
66
61
const props = getProps ( {
67
62
data : {
68
63
items : [ ] ,
69
64
} ,
70
65
} ) ;
71
- const wrapper = shallow ( < Template { ...props } /> , container ) ;
66
+ const wrapper = shallow ( ( < Template { ...props } /> ) as ReactElementLike ) ;
72
67
const onRender = jest . spyOn ( wrapper . instance ( ) , 'render' ) ;
73
68
74
69
wrapper . setProps ( { data : { items : [ ] } } ) ;
@@ -82,7 +77,7 @@ describe('Template', () => {
82
77
items : [ ] ,
83
78
} ,
84
79
} ) ;
85
- const wrapper = shallow ( < Template { ...props } /> , container ) ;
80
+ const wrapper = shallow ( ( < Template { ...props } /> ) as ReactElementLike ) ;
86
81
const onRender = jest . spyOn ( wrapper . instance ( ) , 'render' ) ;
87
82
88
83
wrapper . setProps ( { data : { items : [ 1 ] } } ) ;
@@ -92,7 +87,7 @@ describe('Template', () => {
92
87
93
88
it ( 'calls render when templateKey changes' , ( ) => {
94
89
const props = getProps ( { } ) ;
95
- const wrapper = shallow ( < Template { ...props } /> , container ) ;
90
+ const wrapper = shallow ( ( < Template { ...props } /> ) as ReactElementLike ) ;
96
91
const onRender = jest . spyOn ( wrapper . instance ( ) , 'render' ) ;
97
92
98
93
wrapper . setProps ( {
@@ -107,7 +102,7 @@ describe('Template', () => {
107
102
108
103
it ( 'calls render when rootProps changes' , ( ) => {
109
104
const props = getProps ( { } ) ;
110
- const wrapper = shallow ( < Template { ...props } /> , container ) ;
105
+ const wrapper = shallow ( ( < Template { ...props } /> ) as ReactElementLike ) ;
111
106
const onRender = jest . spyOn ( wrapper . instance ( ) , 'render' ) ;
112
107
113
108
wrapper . setProps ( {
@@ -125,7 +120,7 @@ describe('Template', () => {
125
120
className : 'initialClassName' ,
126
121
} ,
127
122
} ) ;
128
- const wrapper = shallow ( < Template { ...props } /> , container ) ;
123
+ const wrapper = shallow ( ( < Template { ...props } /> ) as ReactElementLike ) ;
129
124
const onRender = jest . spyOn ( wrapper . instance ( ) , 'render' ) ;
130
125
131
126
wrapper . setProps ( {
0 commit comments