-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests for isURIError to unit tests
- Loading branch information
Showing
1 changed file
with
66 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,295 +1,92 @@ | ||
"use strict"; | ||
|
||
var assert = require("assert"); | ||
var referee = require("../referee"); | ||
var captureArgs = require("../test-helper/capture-args"); | ||
|
||
describe("assert.isURIError", function() { | ||
it("should fail for Error", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new Error()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected Error to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for EvalError", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new EvalError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected EvalError to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fal for RangeError", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new RangeError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected RangeError to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for ReferenceError", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new ReferenceError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected ReferenceError to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for SyntaxError", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new SyntaxError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected SyntaxError to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for TypeError", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new TypeError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected TypeError to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should pass for URIError", function() { | ||
referee.assert.isURIError(new URIError()); | ||
}); | ||
|
||
it("should fail for String", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError("apple pie"); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected 'apple pie' to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
var proxyquire = require("proxyquire").noCallThru(); | ||
var sinon = require("sinon"); | ||
|
||
it("should fail for Array", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError([]); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected [] to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for Object", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError({}); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected {} to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
|
||
it("should fail for arguments", function() { | ||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(captureArgs()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] Expected [Arguments] {} to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
var captureArgs = require("../test-helper/capture-args"); | ||
|
||
it("should fail with custom message", function() { | ||
var message = "0bedeb92-f9c8-4440-95f7-e54ab7ecf728"; | ||
describe("isURIError factory", function() { | ||
beforeEach(function() { | ||
this.fakeActualMessageValues = "2e88944c-d6a6-4925-8f74-bb9703f56a51"; | ||
|
||
assert.throws( | ||
function() { | ||
referee.assert.isURIError(new Error(), message); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[assert.isURIError] " + | ||
message + | ||
": Expected Error to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "assert.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
this.factory = proxyquire("./is-uri-error", { | ||
"../actual-message-values": this.fakeActualMessageValues | ||
}); | ||
|
||
describe("refute.isURIError", function() { | ||
it("should pass for Error", function() { | ||
referee.refute.isURIError(new Error()); | ||
}); | ||
this.fakeReferee = { | ||
add: sinon.fake() | ||
}; | ||
|
||
it("should pass for EvalError", function() { | ||
referee.refute.isURIError(new EvalError()); | ||
}); | ||
this.factory(this.fakeReferee); | ||
|
||
it("should pass for RangeError", function() { | ||
referee.refute.isURIError(new RangeError()); | ||
this.options = this.fakeReferee.add.args[0][1]; | ||
}); | ||
|
||
it("should pass for ReferenceError", function() { | ||
referee.refute.isURIError(new ReferenceError()); | ||
it("calls referee.add with 'isURIError' as name", function() { | ||
assert(this.fakeReferee.add.calledWith("isURIError")); | ||
}); | ||
|
||
it("should fail for SyntaxError", function() { | ||
referee.refute.isURIError(new SyntaxError()); | ||
}); | ||
describe(".assert", function() { | ||
context("when called with a URIError instance", function() { | ||
it("returns true", function() { | ||
var result = this.options.assert(new URIError()); | ||
|
||
it("should fail for TypeError", function() { | ||
referee.refute.isURIError(new TypeError()); | ||
}); | ||
assert.equal(result, true); | ||
}); | ||
}); | ||
|
||
it("should pass for URIError", function() { | ||
assert.throws( | ||
function() { | ||
referee.refute.isURIError(new URIError()); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
assert.equal( | ||
error.message, | ||
"[refute.isURIError] Expected URIError not to be a URIError" | ||
); | ||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "refute.isURIError"); | ||
return true; | ||
} | ||
); | ||
}); | ||
context("when called with a non-URIError instance", function() { | ||
it("retunrns false", function() { | ||
var t = this; | ||
var nonWeakSetValues = [ | ||
[], | ||
{}, | ||
"7b210c59-abb9-44b2-8c89-f6d3d5880d0f", | ||
URIError, | ||
new Error(), | ||
new EvalError(), | ||
new RangeError(), | ||
new ReferenceError(), | ||
new SyntaxError(), | ||
new TypeError(), | ||
captureArgs() | ||
]; | ||
|
||
it("should pass for String", function() { | ||
referee.refute.isURIError("apple pie"); | ||
nonWeakSetValues.forEach(function(value) { | ||
assert.equal(t.options.assert(value), false); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should pass for Array", function() { | ||
referee.refute.isURIError([]); | ||
describe(".assertMessage", function() { | ||
it("is '${customMessage}Expected ${actual} to be a URIError'", function() { | ||
assert.equal( | ||
this.options.assertMessage, | ||
"${customMessage}Expected ${actual} to be a URIError" | ||
); | ||
}); | ||
}); | ||
|
||
it("should pass for Object", function() { | ||
referee.refute.isURIError({}); | ||
describe(".refuteMessage", function() { | ||
it("is '${customMessage}Expected ${actual} not to be a URIError'", function() { | ||
assert.equal( | ||
this.options.refuteMessage, | ||
"${customMessage}Expected ${actual} not to be a URIError" | ||
); | ||
}); | ||
}); | ||
|
||
it("should pass for arguments", function() { | ||
referee.refute.isURIError(captureArgs()); | ||
describe(".expectation", function() { | ||
it("is 'toBeURIError'", function() { | ||
assert.equal(this.options.expectation, "toBeURIError"); | ||
}); | ||
}); | ||
|
||
it("should fail with custom message", function() { | ||
var message = "d0150e59-e58d-46c8-b932-e7d0280a0a79"; | ||
|
||
assert.throws( | ||
function() { | ||
referee.refute.isURIError(new URIError(), message); | ||
}, | ||
function(error) { | ||
assert.equal(error.code, "ERR_ASSERTION"); | ||
|
||
assert.equal( | ||
error.message, | ||
"[refute.isURIError] d0150e59-e58d-46c8-b932-e7d0280a0a79: Expected URIError not to be a URIError" | ||
); | ||
|
||
assert.equal(error.name, "AssertionError"); | ||
assert.equal(error.operator, "refute.isURIError"); | ||
return true; | ||
} | ||
); | ||
describe(".values", function() { | ||
it("delegates to '../actual-message-values'", function() { | ||
assert.equal(this.options.values, this.fakeActualMessageValues); | ||
}); | ||
}); | ||
}); |