Skip to content

Commit

Permalink
Use mocha's context feature
Browse files Browse the repository at this point in the history
This improves the readability of tests because the natural reading
direction of English is left to right. Readers will no longer have to
scan back and forth in the first argument to `it` to figure out when this
expectation applies.
  • Loading branch information
mroderick committed Aug 31, 2019
1 parent d61ae17 commit 6a84f51
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions lib/is-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,46 @@ describe("isElement", function() {
isElement = requireWithDOM("./is-element");
});

it("returns true if DOM element node", function() {
var element = document.createElement("div");
var result = isElement(element);
context("when called with a DOM element node", function() {
it("returns true", function() {
var element = document.createElement("div");
var result = isElement(element);

assert.isTrue(result);
assert.isTrue(result);
});
});

it("returns false if DOM text node", function() {
var element = document.createTextNode("Hello");
var result = isElement(element);
context("when called with a DOM text node", function() {
it("returns false", function() {
var element = document.createTextNode("Hello");
var result = isElement(element);

assert.isFalse(result);
assert.isFalse(result);
});
});

it("returns false if node like object", function() {
var nodeLike = { nodeType: 1 };
var result = isElement(nodeLike);
context("when called with a node like object", function() {
it("returns false", function() {
var nodeLike = { nodeType: 1 };
var result = isElement(nodeLike);

assert.isFalse(result);
assert.isFalse(result);
});
});

it("returns false if number", function() {
var result = isElement(42);
context("when called with a number", function() {
it("returns false", function() {
var result = isElement(42);

assert.isFalse(result);
assert.isFalse(result);
});
});

it("returns false if object", function() {
var result = isElement({});
context("when called with an object", function() {
it("returns false", function() {
var result = isElement({});

assert.isFalse(result);
assert.isFalse(result);
});
});
});

0 comments on commit 6a84f51

Please sign in to comment.