Add tests for the Handlebars helper equal

This commit is contained in:
Jérémie Astori 2017-12-21 20:09:12 -05:00
parent da7481c23c
commit 6d053d65e7
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
2 changed files with 31 additions and 0 deletions

View File

@ -1,8 +1,13 @@
"use strict";
module.exports = function(a, b, opt) {
if (arguments.length !== 3) {
throw new Error("Handlebars helper `equal` expects 3 arguments");
}
a = a.toString();
b = b.toString();
if (a === b) {
return opt.fn(this);
}

View File

@ -0,0 +1,26 @@
"use strict";
const expect = require("chai").expect;
const equal = require("../../../../../client/js/libs/handlebars/equal");
describe("equal Handlebars helper", function() {
const block = {
fn: () => "fn",
inverse: () => "inverse",
};
it("should render the first block if both values are equal", function() {
expect(equal("foo", "foo", block)).to.equal("fn");
});
it("should render the inverse block if values are not equal", function() {
expect(equal("foo", "bar", block)).to.equal("inverse");
});
it("should throw if too few or too many arguments are given", function() {
expect(() => equal("foo", block)).to.throw(Error, /expects 3 arguments/);
expect(() => equal("foo", "bar", "baz", block))
.to.throw(Error, /expects 3 arguments/);
});
});