Skip to content

Commit 77825f8

Browse files
authored
refator: In spec tests, use expectTemplate over equals and shouldThrow (#1683)
1 parent 3789a30 commit 77825f8

17 files changed

+3350
-4124
lines changed

spec/basic.js

+389-401
Large diffs are not rendered by default.

spec/blocks.js

+288-337
Large diffs are not rendered by default.

spec/builtins.js

+447-443
Large diffs are not rendered by default.

spec/data.js

+158-244
Large diffs are not rendered by default.

spec/env/common.js

+40-7
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function HandlebarsTestBench(templateAsString) {
129129
this.templateAsString = templateAsString;
130130
this.helpers = {};
131131
this.partials = {};
132+
this.decorators = {};
132133
this.input = {};
133134
this.message =
134135
'Template' + templateAsString + ' does not evaluate to expected output';
@@ -146,11 +147,43 @@ HandlebarsTestBench.prototype.withHelper = function(name, helperFunction) {
146147
return this;
147148
};
148149

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+
149158
HandlebarsTestBench.prototype.withPartial = function(name, partialAsString) {
150159
this.partials[name] = partialAsString;
151160
return this;
152161
};
153162

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+
154187
HandlebarsTestBench.prototype.withCompileOptions = function(compileOptions) {
155188
this.compileOptions = compileOptions;
156189
return this;
@@ -167,19 +200,18 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
167200
};
168201

169202
HandlebarsTestBench.prototype.toCompileTo = function(expectedOutputAsString) {
170-
expect(this._compileAndExecute()).to.equal(expectedOutputAsString);
203+
expect(this._compileAndExecute()).to.equal(
204+
expectedOutputAsString,
205+
this.message
206+
);
171207
};
172208

173209
// 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) {
179211
var self = this;
180212
expect(function() {
181213
self._compileAndExecute();
182-
}).to.throw(errorLike, errMsgMatcher, msg);
214+
}).to.throw(errorLike, errMsgMatcher, this.message);
183215
};
184216

185217
HandlebarsTestBench.prototype._compileAndExecute = function() {
@@ -202,5 +234,6 @@ HandlebarsTestBench.prototype._combineRuntimeOptions = function() {
202234
});
203235
combinedRuntimeOptions.helpers = this.helpers;
204236
combinedRuntimeOptions.partials = this.partials;
237+
combinedRuntimeOptions.decorators = this.decorators;
205238
return combinedRuntimeOptions;
206239
};

0 commit comments

Comments
 (0)