@@ -142,24 +142,35 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
142142} ;
143143
144144HandlebarsTestBench . 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 ) {
145150 var self = this ;
151+ expect ( function ( ) {
152+ self . _compileAndExeute ( ) ;
153+ } ) . to . throw ( errorLike , errMsgMatcher , msg ) ;
154+ } ;
155+
156+ HandlebarsTestBench . prototype . _compileAndExeute = function ( ) {
146157 var compile = Object . keys ( this . partials ) . length > 0
147158 ? CompilerContext . compileWithPartial
148159 : CompilerContext . compile ;
149160
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 ;
150169 var combinedRuntimeOptions = { } ;
151170 Object . keys ( this . runtimeOptions ) . forEach ( function ( key ) {
152171 combinedRuntimeOptions [ key ] = self . runtimeOptions [ key ] ;
153172 } ) ;
154173 combinedRuntimeOptions . helpers = this . helpers ;
155174 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 ;
165176} ;
0 commit comments