Skip to content

Commit

Permalink
Install prettier, eslint-config-prettier, eslint-plugin-prettier
Browse files Browse the repository at this point in the history
And fix all lint violations

This gives referee the same configuration as samsam
  • Loading branch information
Morgan Roderick authored and mroderick committed Jul 30, 2018
1 parent cd2984c commit b98bcb4
Show file tree
Hide file tree
Showing 75 changed files with 2,190 additions and 1,016 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extends: 'eslint-config-sinon'
extends:
- 'eslint-config-sinon'
- 'plugin:prettier/recommended'

env:
browser: true
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
10 changes: 8 additions & 2 deletions lib/assert-arg-num.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ function assertArgNum(defaultFail, name, args, num, customFail) {
var fail = customFail || defaultFail;

if (args.length < num) {
fail("[" + name + "] Expected to receive at least " +
num + " argument" + (num > 1 ? "s" : ""));
fail(
"[" +
name +
"] Expected to receive at least " +
num +
" argument" +
(num > 1 ? "s" : "")
);
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/assert-equals-host-objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ if (typeof document === "undefined") {
return;
}

describe("assert.equals host objects", function () {
beforeEach(function () {
describe("assert.equals host objects", function() {
beforeEach(function() {
sandbox.spy(referee, "fail");

referee.format = sandbox.spy(function (object) {
referee.format = sandbox.spy(function(object) {
return String(object);
});

Expand All @@ -22,24 +22,24 @@ describe("assert.equals host objects", function () {
referee.on("failure", this.failListener);
});

afterEach(function () {
afterEach(function() {
sandbox.restore();
delete referee.listeners;
referee.count = 0;
delete referee.throwOnFailure;
});

it("should pass when comparing DOM element to itself", function () {
it("should pass when comparing DOM element to itself", function() {
var element = document.createElement("div");

referee.assert.equals(element, element);
});

it("should fail when comparing different DOM elements", function () {
it("should fail when comparing different DOM elements", function() {
var div = document.createElement("div");
var span = document.createElement("span");

referee.assert.exception(function () {
referee.assert.exception(function() {
referee.assert.equals(div, span);
});
});
Expand Down
44 changes: 29 additions & 15 deletions lib/assert-exception-unexpected-exception.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,44 @@

var referee = require("./referee");

describe("assert.exception unexpected exception", function () {
it("fails with custom message", function () {
describe("assert.exception unexpected exception", function() {
it("fails with custom message", function() {
try {
referee.assert.exception(function () {
throw new Error(":(");
}, { name: "TypeError" }, "Wow");
referee.assert.exception(
function() {
throw new Error(":(");
},
{ name: "TypeError" },
"Wow"
);
throw new Error("Expected to throw");
} catch (e) {
referee.assert.match(e.message, "[assert.exception] Wow: Expected " +
"[object Object] but threw Error " +
"(:()\nError: :(\n");
referee.assert.match(
e.message,
"[assert.exception] Wow: Expected " +
"[object Object] but threw Error " +
"(:()\nError: :(\n"
);
}
});

it("fails with custom message when message is wrong", function () {
it("fails with custom message when message is wrong", function() {
try {
referee.assert.exception(function () {
throw new Error(":(");
}, { name: "Error", message: "Aww" }, "Wow");
referee.assert.exception(
function() {
throw new Error(":(");
},
{ name: "Error", message: "Aww" },
"Wow"
);
throw new Error("Expected to throw");
} catch (e) {
referee.assert.match(e.message, "[assert.exception] Wow: Expected " +
"[object Object] but threw " +
"Error (:()\nError: :(\n");
referee.assert.match(
e.message,
"[assert.exception] Wow: Expected " +
"[object Object] but threw " +
"Error (:()\nError: :(\n"
);
}
});
});
63 changes: 36 additions & 27 deletions lib/assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
var sandbox = require("sinon").createSandbox();
var referee = require("../lib/referee");

describe("assert", function () {
beforeEach(function () {
describe("assert", function() {
beforeEach(function() {
sandbox.spy(referee, "fail");

referee.format = sandbox.spy(function (object) {
referee.format = sandbox.spy(function(object) {
return String(object);
});

Expand All @@ -17,14 +17,14 @@ describe("assert", function () {
referee.on("failure", this.failListener);
});

afterEach(function () {
afterEach(function() {
sandbox.restore();
delete referee.listeners;
referee.count = 0;
delete referee.throwOnFailure;
});

it("allows true", function () {
it("allows true", function() {
var okListener = sandbox.spy();
referee.on("pass", okListener);

Expand All @@ -34,63 +34,69 @@ describe("assert", function () {
sandbox.assert.calledWith(okListener, "assert");
});

it("allows truthy values", function () {
it("allows truthy values", function() {
referee.assert({});
referee.assert([]);
referee.assert("Truthy");
referee.assert(1);
referee.assert(/a/);
});

it("allows true with message", function () {
it("allows true with message", function() {
referee.assert(true, "s'aright");
});

it("does not allow false", function () {
referee.assert.exception(function () {
referee.assert(false);
}, {message: "[assert] Expected false to be truthy"});
it("does not allow false", function() {
referee.assert.exception(
function() {
referee.assert(false);
},
{ message: "[assert] Expected false to be truthy" }
);
});

it("does not allow falsy values", function () {
referee.assert.exception(function () {
it("does not allow falsy values", function() {
referee.assert.exception(function() {
referee.assert("");
});

referee.assert.exception(function () {
referee.assert.exception(function() {
referee.assert(0);
});

referee.assert.exception(function () {
referee.assert.exception(function() {
referee.assert(NaN);
});

referee.assert.exception(function () {
referee.assert.exception(function() {
referee.assert(null);
});

referee.assert.exception(function () {
referee.assert.exception(function() {
referee.assert(undefined);
});
});

it("does not allow false with message", function () {
referee.assert.exception(function () {
it("does not allow false with message", function() {
referee.assert.exception(function() {
referee.assert(false, "Some message");
});
});

it("fails with generated message", function () {
it("fails with generated message", function() {
try {
referee.assert(false);
throw new Error("Didn't fail");
} catch (e) {
referee.assert.equals(e.name, "AssertionError");
referee.assert.equals(e.message, "[assert] Expected false to be truthy");
referee.assert.equals(
e.message,
"[assert] Expected false to be truthy"
);
}
});

it("fails with custom message", function () {
it("fails with custom message", function() {
try {
referee.assert(false, "False FTW");
throw new Error("Didn't fail");
Expand All @@ -100,28 +106,31 @@ describe("assert", function () {
}
});

it("updates assertion count", function () {
it("updates assertion count", function() {
referee.count = 0;

try {
referee.assert(true);
referee.assert(false);
// eslint-disable-next-line no-empty
// eslint-disable-next-line no-empty
} catch (e) {}

referee.assert.equals(referee.count, 2);
});

it("fails if not passed arguments", function () {
it("fails if not passed arguments", function() {
try {
referee.assert();
throw new Error("Expected assert to fail");
} catch (e) {
referee.assert.equals(e.message, "[assert] Expected to receive at least 1 argument");
referee.assert.equals(
e.message,
"[assert] Expected to receive at least 1 argument"
);
}
});

it("does not throw if not configured to", function () {
it("does not throw if not configured to", function() {
referee.throwOnFailure = false;
referee.assert(false);
});
Expand Down
18 changes: 11 additions & 7 deletions lib/assertions/class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var includes = require("lodash.includes");

module.exports = function (referee) {
module.exports = function(referee) {
referee.add("className", {
assert: function (element, name) {
assert: function(element, name) {
if (typeof element.className === "undefined") {
return this.fail("noClassNameMessage");
}
Expand All @@ -20,11 +20,13 @@ module.exports = function (referee) {

return true;
},
assertMessage: "${customMessage}Expected object's className to include ${expected} " +
assertMessage:
"${customMessage}Expected object's className to include ${expected} " +
"but was ${actual}",
refuteMessage: "${customMessage}Expected object's className not to include ${expected}",
refuteMessage:
"${customMessage}Expected object's className not to include ${expected}",
expectation: "toHaveClassName",
values: function (element, className, message) {
values: function(element, className, message) {
return {
actualElement: element,
actual: element.className,
Expand All @@ -34,6 +36,8 @@ module.exports = function (referee) {
}
});

referee.assert.className.noClassNameMessage = "${customMessage}Expected object to have className property";
referee.refute.className.noClassNameMessage = "${customMessage}Expected object to have className property";
referee.assert.className.noClassNameMessage =
"${customMessage}Expected object to have className property";
referee.refute.className.noClassNameMessage =
"${customMessage}Expected object to have className property";
};
10 changes: 6 additions & 4 deletions lib/assertions/contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
var includes = require("lodash.includes");
var actualAndExpectedMessageValues = require("../actual-and-expected-message-values");

module.exports = function (referee) {
module.exports = function(referee) {
referee.add("contains", {
assert: function (haystack, needle) {
assert: function(haystack, needle) {
return includes(haystack, needle);
},
assertMessage: "${customMessage}Expected [${actual}] to contain ${expected}",
refuteMessage: "${customMessage}Expected [${actual}] not to contain ${expected}",
assertMessage:
"${customMessage}Expected [${actual}] to contain ${expected}",
refuteMessage:
"${customMessage}Expected [${actual}] not to contain ${expected}",
expectation: "toContain",
values: actualAndExpectedMessageValues
});
Expand Down
7 changes: 4 additions & 3 deletions lib/assertions/defined.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

var actualAndTypeOfMessageValues = require("../actual-and-type-of-message-values");

module.exports = function (referee) {
module.exports = function(referee) {
referee.add("defined", {
assert: function (actual) {
assert: function(actual) {
return typeof actual !== "undefined";
},
assertMessage: "${customMessage}Expected to be defined",
refuteMessage: "${customMessage}Expected ${actual} (${actualType}) not to be defined",
refuteMessage:
"${customMessage}Expected ${actual} (${actualType}) not to be defined",
expectation: "toBeDefined",
values: actualAndTypeOfMessageValues
});
Expand Down
Loading

0 comments on commit b98bcb4

Please sign in to comment.