Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In spec tests, use expectTemplate over equals and shouldThrow #1683

Merged
merged 11 commits into from
May 4, 2020
790 changes: 389 additions & 401 deletions spec/basic.js

Large diffs are not rendered by default.

625 changes: 288 additions & 337 deletions spec/blocks.js

Large diffs are not rendered by default.

890 changes: 447 additions & 443 deletions spec/builtins.js

Large diffs are not rendered by default.

402 changes: 158 additions & 244 deletions spec/data.js

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions spec/env/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function HandlebarsTestBench(templateAsString) {
this.templateAsString = templateAsString;
this.helpers = {};
this.partials = {};
this.decorators = {};
this.input = {};
this.message =
'Template' + templateAsString + ' does not evaluate to expected output';
Expand All @@ -146,11 +147,43 @@ HandlebarsTestBench.prototype.withHelper = function(name, helperFunction) {
return this;
};

HandlebarsTestBench.prototype.withHelpers = function(helperFunctions) {
var self = this;
Object.keys(helperFunctions).forEach(function(name) {
self.withHelper(name, helperFunctions[name]);
});
return this;
};

HandlebarsTestBench.prototype.withPartial = function(name, partialAsString) {
this.partials[name] = partialAsString;
return this;
};

HandlebarsTestBench.prototype.withPartials = function(partials) {
var self = this;
Object.keys(partials).forEach(function(name) {
self.withPartial(name, partials[name]);
});
return this;
};

HandlebarsTestBench.prototype.withDecorator = function(
name,
decoratorFunction
) {
this.decorators[name] = decoratorFunction;
return this;
};

HandlebarsTestBench.prototype.withDecorators = function(decorators) {
var self = this;
Object.keys(decorators).forEach(function(name) {
self.withDecorator(name, decorators[name]);
});
return this;
};

HandlebarsTestBench.prototype.withCompileOptions = function(compileOptions) {
this.compileOptions = compileOptions;
return this;
Expand All @@ -167,19 +200,18 @@ HandlebarsTestBench.prototype.withMessage = function(message) {
};

HandlebarsTestBench.prototype.toCompileTo = function(expectedOutputAsString) {
expect(this._compileAndExecute()).to.equal(expectedOutputAsString);
expect(this._compileAndExecute()).to.equal(
expectedOutputAsString,
this.message
);
};

// see chai "to.throw" (https://www.chaijs.com/api/bdd/#method_throw)
HandlebarsTestBench.prototype.toThrow = function(
errorLike,
errMsgMatcher,
msg
) {
HandlebarsTestBench.prototype.toThrow = function(errorLike, errMsgMatcher) {
var self = this;
expect(function() {
self._compileAndExecute();
}).to.throw(errorLike, errMsgMatcher, msg);
}).to.throw(errorLike, errMsgMatcher, this.message);
};

HandlebarsTestBench.prototype._compileAndExecute = function() {
Expand All @@ -202,5 +234,6 @@ HandlebarsTestBench.prototype._combineRuntimeOptions = function() {
});
combinedRuntimeOptions.helpers = this.helpers;
combinedRuntimeOptions.partials = this.partials;
combinedRuntimeOptions.decorators = this.decorators;
return combinedRuntimeOptions;
};
Loading