@@ -98,14 +98,35 @@ describe('PluginImpl', () => {
98
98
return expect . stringMatching ( new RegExp ( `^;{${ numLines } }` ) )
99
99
}
100
100
101
+ expect . extend ( {
102
+ toStartWith ( received , expected ) {
103
+ const actual = received . substring ( 0 , expected . length )
104
+ return {
105
+ pass : actual === expected ,
106
+ message : ( ) => 'expected string to begin with expected prefix' ,
107
+ actual,
108
+ expected
109
+ }
110
+ } ,
111
+ toEndWith ( received , expected ) {
112
+ const actual = received . substring ( received . length - expected . length )
113
+ return {
114
+ pass : actual === expected ,
115
+ message : ( ) => 'expected string to end with expected suffix' ,
116
+ actual,
117
+ expected
118
+ }
119
+ }
120
+ } )
121
+
101
122
test ( 'emits precompiled template module and source map' , ( ) => {
102
123
const impl = new PluginImpl ( )
103
124
104
125
const { code, map } = impl . compile ( templateStr , 'foo.hbs' )
105
126
106
127
const expectedPrefix = `${ PREFIX } \n${ BEGIN_TEMPLATE } `
107
- expect ( code . substring ( 0 , expectedPrefix . length ) ) . toBe ( expectedPrefix )
108
- expect ( code . substring ( code . length - SUFFIX . length ) ) . toBe ( SUFFIX )
128
+ expect ( code ) . toStartWith ( expectedPrefix )
129
+ expect ( code ) . toEndWith ( SUFFIX )
109
130
expect ( map ) . toMatchObject ( {
110
131
sources : [ 'foo.hbs' ] ,
111
132
mappings : mappingSkipsPrefix ( expectedPrefix )
@@ -132,5 +153,69 @@ describe('PluginImpl', () => {
132
153
expect ( map ) . toHaveProperty ( 'sources' , [ 'foo.hbs' ] )
133
154
expect ( map ) . not . toHaveProperty ( 'file' )
134
155
} )
156
+
157
+ describe ( 'imports partials using' , ( ) => {
158
+ const templateStr = '{{>bar}}{{>baz}}{{>quux}}'
159
+
160
+ test ( 'DEFAULT_PARTIAL_PATH' , ( ) => {
161
+ const impl = new PluginImpl ( )
162
+
163
+ const { code, map } = impl . compile ( templateStr , 'foo.hbs' )
164
+
165
+ const expectedPrefix = [
166
+ PREFIX ,
167
+ 'import \'./_bar.hbs\'' ,
168
+ 'import \'./_baz.hbs\'' ,
169
+ 'import \'./_quux.hbs\'' ,
170
+ BEGIN_TEMPLATE
171
+ ] . join ( '\n' )
172
+ expect ( code ) . toStartWith ( expectedPrefix )
173
+ expect ( code ) . toEndWith ( SUFFIX )
174
+ expect ( map ) . toMatchObject ( {
175
+ sources : [ 'foo.hbs' ] ,
176
+ mappings : mappingSkipsPrefix ( expectedPrefix )
177
+ } )
178
+ } )
179
+
180
+ test ( 'custom options.partialPath' , ( ) => {
181
+ const impl = new PluginImpl ( {
182
+ partialPath : ( partialName ) => `./${ partialName } .partial.hbs`
183
+ } )
184
+
185
+ const { code } = impl . compile ( templateStr , 'foo.hbs' )
186
+
187
+ const expectedPrefix = [
188
+ PREFIX ,
189
+ 'import \'./bar.partial.hbs\'' ,
190
+ 'import \'./baz.partial.hbs\'' ,
191
+ 'import \'./quux.partial.hbs\'' ,
192
+ BEGIN_TEMPLATE
193
+ ] . join ( '\n' )
194
+ expect ( code ) . toStartWith ( expectedPrefix )
195
+ } )
196
+ } )
197
+
198
+ describe ( 'registers partials using' , ( ) => {
199
+ test ( 'DEFAULT_PARTIALS filter and DEFAULT_PARTIAL_NAME' , ( ) => {
200
+ const impl = new PluginImpl ( )
201
+
202
+ const { code } = impl . compile ( templateStr , '_foo.hbs' )
203
+
204
+ const expected = 'Handlebars.registerPartial(\'foo\', RawTemplate)'
205
+ expect ( code ) . toEndWith ( `${ SUFFIX } \n${ expected } ` )
206
+ } )
207
+
208
+ test ( 'custom options.partials and options.partialName' , ( ) => {
209
+ const impl = new PluginImpl ( {
210
+ partials : '**/*.partial.hbs' ,
211
+ partialName ( id ) { return id . replace ( / \. p a r t i a l \. h b s $ / , '' ) }
212
+ } )
213
+
214
+ const { code } = impl . compile ( templateStr , 'foo.partial.hbs' )
215
+
216
+ const expected = 'Handlebars.registerPartial(\'foo\', RawTemplate)'
217
+ expect ( code ) . toEndWith ( `${ SUFFIX } \n${ expected } ` )
218
+ } )
219
+ } )
135
220
} )
136
221
} )
0 commit comments