@@ -142,24 +142,35 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
142
142
} ;
143
143
144
144
HandlebarsTestBench . prototype . toCompileTo = function ( expectedOutputAsString ) {
145
+ expect ( this . _compileAndExeute ( ) ) . to . equal ( expectedOutputAsString ) ;
146
+ } ;
147
+
148
+ // see chai "to.throw" (https://www.chaijs.com/api/bdd/#method_throw)
149
+ HandlebarsTestBench . prototype . toThrow = function ( errorLike , errMsgMatcher , msg ) {
145
150
var self = this ;
151
+ expect ( function ( ) {
152
+ self . _compileAndExeute ( ) ;
153
+ } ) . to . throw ( errorLike , errMsgMatcher , msg ) ;
154
+ } ;
155
+
156
+ HandlebarsTestBench . prototype . _compileAndExeute = function ( ) {
146
157
var compile = Object . keys ( this . partials ) . length > 0
147
158
? CompilerContext . compileWithPartial
148
159
: CompilerContext . compile ;
149
160
161
+ var combinedRuntimeOptions = this . _combineRuntimeOptions ( ) ;
162
+
163
+ var template = compile ( this . templateAsString , this . compileOptions ) ;
164
+ return template ( this . input , combinedRuntimeOptions ) ;
165
+ } ;
166
+
167
+ HandlebarsTestBench . prototype . _combineRuntimeOptions = function ( ) {
168
+ var self = this ;
150
169
var combinedRuntimeOptions = { } ;
151
170
Object . keys ( this . runtimeOptions ) . forEach ( function ( key ) {
152
171
combinedRuntimeOptions [ key ] = self . runtimeOptions [ key ] ;
153
172
} ) ;
154
173
combinedRuntimeOptions . helpers = this . helpers ;
155
174
combinedRuntimeOptions . partials = this . partials ;
156
-
157
- var template = compile ( this . templateAsString , this . compileOptions ) ;
158
- var output = template ( this . input , combinedRuntimeOptions ) ;
159
-
160
- if ( output !== expectedOutputAsString ) {
161
- // Error message formatted so that IntelliJ-Idea shows "diff"-button
162
- // https://stackoverflow.com/a/10945655/4251384
163
- throw new AssertError ( this . message + '\nexpected:' + expectedOutputAsString + 'but was:' + output ) ;
164
- }
175
+ return combinedRuntimeOptions ;
165
176
} ;
0 commit comments