@@ -129,6 +129,7 @@ function HandlebarsTestBench(templateAsString) {
129
129
this . templateAsString = templateAsString ;
130
130
this . helpers = { } ;
131
131
this . partials = { } ;
132
+ this . decorators = { } ;
132
133
this . input = { } ;
133
134
this . message =
134
135
'Template' + templateAsString + ' does not evaluate to expected output' ;
@@ -146,11 +147,43 @@ HandlebarsTestBench.prototype.withHelper = function(name, helperFunction) {
146
147
return this ;
147
148
} ;
148
149
150
+ HandlebarsTestBench . prototype . withHelpers = function ( helperFunctions ) {
151
+ var self = this ;
152
+ Object . keys ( helperFunctions ) . forEach ( function ( name ) {
153
+ self . withHelper ( name , helperFunctions [ name ] ) ;
154
+ } ) ;
155
+ return this ;
156
+ } ;
157
+
149
158
HandlebarsTestBench . prototype . withPartial = function ( name , partialAsString ) {
150
159
this . partials [ name ] = partialAsString ;
151
160
return this ;
152
161
} ;
153
162
163
+ HandlebarsTestBench . prototype . withPartials = function ( partials ) {
164
+ var self = this ;
165
+ Object . keys ( partials ) . forEach ( function ( name ) {
166
+ self . withPartial ( name , partials [ name ] ) ;
167
+ } ) ;
168
+ return this ;
169
+ } ;
170
+
171
+ HandlebarsTestBench . prototype . withDecorator = function (
172
+ name ,
173
+ decoratorFunction
174
+ ) {
175
+ this . decorators [ name ] = decoratorFunction ;
176
+ return this ;
177
+ } ;
178
+
179
+ HandlebarsTestBench . prototype . withDecorators = function ( decorators ) {
180
+ var self = this ;
181
+ Object . keys ( decorators ) . forEach ( function ( name ) {
182
+ self . withDecorator ( name , decorators [ name ] ) ;
183
+ } ) ;
184
+ return this ;
185
+ } ;
186
+
154
187
HandlebarsTestBench . prototype . withCompileOptions = function ( compileOptions ) {
155
188
this . compileOptions = compileOptions ;
156
189
return this ;
@@ -167,19 +200,18 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
167
200
} ;
168
201
169
202
HandlebarsTestBench . prototype . toCompileTo = function ( expectedOutputAsString ) {
170
- expect ( this . _compileAndExecute ( ) ) . to . equal ( expectedOutputAsString ) ;
203
+ expect ( this . _compileAndExecute ( ) ) . to . equal (
204
+ expectedOutputAsString ,
205
+ this . message
206
+ ) ;
171
207
} ;
172
208
173
209
// see chai "to.throw" (https://www.chaijs.com/api/bdd/#method_throw)
174
- HandlebarsTestBench . prototype . toThrow = function (
175
- errorLike ,
176
- errMsgMatcher ,
177
- msg
178
- ) {
210
+ HandlebarsTestBench . prototype . toThrow = function ( errorLike , errMsgMatcher ) {
179
211
var self = this ;
180
212
expect ( function ( ) {
181
213
self . _compileAndExecute ( ) ;
182
- } ) . to . throw ( errorLike , errMsgMatcher , msg ) ;
214
+ } ) . to . throw ( errorLike , errMsgMatcher , this . message ) ;
183
215
} ;
184
216
185
217
HandlebarsTestBench . prototype . _compileAndExecute = function ( ) {
@@ -202,5 +234,6 @@ HandlebarsTestBench.prototype._combineRuntimeOptions = function() {
202
234
} ) ;
203
235
combinedRuntimeOptions . helpers = this . helpers ;
204
236
combinedRuntimeOptions . partials = this . partials ;
237
+ combinedRuntimeOptions . decorators = this . decorators ;
205
238
return combinedRuntimeOptions ;
206
239
} ;
0 commit comments