Skip to content

Commit

Permalink
refator: In spec tests, use expectTemplate over equals and shouldThrow (
Browse files Browse the repository at this point in the history
  • Loading branch information
jbboehr authored May 4, 2020
1 parent 3789a30 commit 77825f8
Show file tree
Hide file tree
Showing 17 changed files with 3,350 additions and 4,124 deletions.
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

0 comments on commit 77825f8

Please sign in to comment.