Add tests for the Handlebars helper equal
This commit is contained in:
parent
da7481c23c
commit
6d053d65e7
@ -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);
|
||||
}
|
||||
|
26
test/client/js/libs/handlebars/equalTest.js
Normal file
26
test/client/js/libs/handlebars/equalTest.js
Normal 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/);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user