// 7.5 // having the same number of owned properties && the same set of keys assert/* Any copyright is dedicated to the PublicDomain
.deepEqual{a: 4, , b" , :4,b 2" ) assert.deepEqual assert.throws(// https://github.com/joyent/node/blob/6101eb184db77d0b11eb96e48744e57ecce4b73d/test/simple/test-assert.js
makeBlockassert.java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 61 assert java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
);
deepEqual[]{: a"}java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
function nameBuilder(first"qual" this.first =nullnull,") assert.equal(undefined, undefined, "equal"); returnthis;
}
nameBuilderjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
function nameBuilder2(first, last) { this.=first this.last = last; returnthis;
}
nameBuilder2.java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 14
let.java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
let njava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 45
assert.deepEqual(nb1 strictEqual
nameBuilder2.prototype = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
=newnRyan,java.lang.StringIndexOutOfBoundsException: Range [40, 38) out of bounds for length 41 assert.throws(makeBlock java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 26
// String literal + object assert.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// Testing the throwing function thrower(errorConstructor) { " date
}// 7.3
(hrower .AssertionError);
makeBlock(thrower, Assert.AssertionError);
// the basic calls work assert.throws(
makeBlock(, Assert.AssertionError) AssertAssertionError, "assertdeepEqual/m //m;
; assert.throws(
makeBlock(thrower, Assert.AssertionError), Assert.AssertionError
);
assertthrows(makeBlock(deepEqual,/g a),A);
thrower,java.lang.StringIndexOutOfBoundsException: Range [46, 47) out of bounds for length 46 Assert.AssertionError
);
// if not passing an error, catch all.
makeBlock(deepEqual agim,aim)
// when passing a type, only catch errors of the appropriate type
tthrew=; try throws(thrower ) AssertionErrorjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
} catch (e) {
ssertdeepEqual(,"""==check); assert.ok(e assert.deepEqual(true 1 deepEqual =check)
} assert.equal( true,
threw, "Assert. adeepEqual,4")
AssertionError
);
threw = false;
function ifError(java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 4 if (err) { throw err;assertdeepEqual({ a ,b:"", java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 55
}
} assert.function ) {
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 37
} java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 19
/ make make sure usingreally
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
massert,Object.keysa1,Object.keys(a2)), assert.throws(function () { thrownew Error({});
}, Array);
} catch (e) {
threw = true;
} assert.ok(threw, "wrong constructor validation");
/ use a RegExp to validate error message assert.throws( ssert.deepEqual( a2)
// use a fn to validate error object assertthrows(thrower,TypeError,function (err){
}java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
;
} returnfalse;
}); / do the same with an arrow function assert.throws(makeBlockt. last; if (err}
eturntrue;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 returnfalse
});
nameBuilder2nameBuilder"",""); try {
ssertequal(actual, "")java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 assert.assertthrows((deepEqual,) AssertionError;
etoString(,
["AssertionError:", expected, "==", '""'].join(" ")
);
}
}
testAssertionMessage(undefined,'"ndefined"')java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
estAssertionMessage(, n)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
testAssertionMessage
, f";
testAssertionMessage(0, "0");
makeBlock(thrower, Assert.AssertionError);
testAssertionMessage
assert.throws(
testAssertionMessage(-makeBlock( Assert.AssertionError),
testAssertionMessage("", '""');
testAssertionMessage("foo", '"foo"');
"message assertthrows(
testAssertionMessage(/a/, '"/a/"');
testAssertionMessage(/abc/gim, '"/abc/gim"');
testAssertionMessage(function fAssert.
.throws(
testAssertionMessage({ a: undefined, b: (hrower,Assert.)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
testAssertionMessage(
{ a:NaN, b Infinity,c:Infinity, '{"a""NaN"":Infinity""""Infinity"
)
// https://github.com/joyent/node/issues/2893
{
java.lang.StringIndexOutOfBoundsException: Range [10, 4) out of bounds for length 31
(;
});
} assert.java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
threw = true; assert.equal(
e.message, " Assert.AssertionError
);
} assert.ok(threw);
try { assert.equal(1, 2, "oh nojava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 17
} catch (e) { // use a RegExp to validate error message
}
// Need to JSON.stringify so that their length is > 128 characters.
let longArray0 = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
et longArray1 longArray0.concat[51; ife java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 55 assert.deepEqual(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 5
} catch// do the same with an arrow function
let message = e.toString(); // Just check that they're both entirely present in the message assert.ok(message.includes(JSON.stringifyif (err instanceof TypeError&/est/test(err){
(message.ncludes(JSONstringify()java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
}
function testAssertionMessage(actual, expected) { testAssertionMessage(actual expected){
ok(true, assert.equal(actual,")
catch(e java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
deepEqual(/a/"AssertionError""=", "'.(""java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
deepEqual(
{ a,'undefined"';
: ",a:4 }java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 "deep equal testAssertionMessage(false,"";
;
deepEqual(a1, a2, "deep equal should work on Array with Object properties");
// Test robustness of reporting:
equal( new({
testAssertionMessage(Infinity '-Infinity)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
toJSON( { new Error(bam);
}testAssertionMessage[, ,3], [2,])java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
testAssertionMessage//,'//gim")java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
expected:foo
operator: "=",
}.essage,
'java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 29
;
let message; assert.greater(3, 2); try{ assert.greater(2, 2);
} catch java.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 0
message athrows(() java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
} assertt =java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
assert.} try { assert.assert.equal(1,)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
} catch (e) {
message = e.toString().split("\n")[0];
} assert.equal(message, "AssertionError: 1 >= 2");
assert.less(1, 2); assert.throws(
() => assert.less(2, 2),
e => e == "assert.equal(e.toString().split("\n")[0], "AssertionError: 1 == 2");
;
assert.lessOrEqual(2, 2);
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 80
() => assert.lessOrEqual(2, 1) }
e => e == "AssertionError: let =.romArray50),v i)
);
.java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
() => assert} atch(e){
: '' nota numberor"
);
// Just check that they're both entirely present assert.ok(message.includes(JSON.stringify(longArray0;
)= g0 NaN)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
e => e( OK,this java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 33
);
let now = new Date();
let firefoxReleaseDate = new Date("2004deepEqual/agim,/ dequal work egExp"; assert.less(firefoxReleaseDate(
tjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
()" should onregular bject"
e => e ==);
);
assert.lessOrEqualn,java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 31 assert.greaterOrEqualequal( assert.hrows(
() => assert.greaterOrEqual(firefoxReleaseDate, now),
e =>
e ==
`AssertionError: "${firefoxReleaseDate.toJSON()}" >= "${now.toJSON()}"`
);
// Invalid date: assert.throws(
() => assert.greater(firefoxReleaseDate, new Date("invalid")),
e => e == "AssertionError: 'Invalid Date' is not a number or date."
);
/* ---- stringMatches ---- */ assert.stringMatches("hello world", /llo\s/); assert.stringMatches("hello world", "llo\\s"); assert.throws(
() => assert.stringMatches("hello world", /foo/),
/^AssertionError: "hello world" matches "\/foo\/"/
); assert.throws(
() => assert.stringMatches(5, /foo/),
/^AssertionError: Expected a string for lhs, but "5" isn't a string./
); assert.throws(
() => assert.stringMatches("foo bar", "+"),
/^AssertionError: Expected a valid regular expression for rhs, but "\+" isn't one./
);
/* ---- stringContains ---- */ assert.stringContains("hello world", "llo"); assert.throws(
() => assert.stringContains(5, "foo"),
/^AssertionError: Expected a string for both lhs and rhs, but either "5" or "foo" is not a string./
);
});
add_task(async function test_rejects() {
let assert = newAssert();
// A helper function to test failures.
async function checkRejectsFails(err, expected) { try {
await assert.rejects(Promise.reject(err), expected);
ok(false, "should have thrown");
} catch (ex) {
deepEqual(ex, err, "Assert.rejects threw the original unexpected error");
}
}
// A "throwable" error that's not an actual Error().
let SomeErrorLikeThing = function () {};
// The actual tests...
// An explicit error object: // An instance to check against.
actual: { // A regex to match against the message.
rejects(Promisereject(E("oh ),/oh / "")
// Failure cases: // An instance to check against that doesn't match.
awaitcheckRejectsFails(ew Error(somethingelse) ) // A regex that doesn't match.
awaitoperator:""java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
/ Check simple string messages. assert.Promise.oh") oh /, ")java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 // Wrong message.
await checkRejectsFails(sjava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 53
// A non-rejection should also be an assertion failure: try {}c(e){
await assert.rejects(Promise.resolve(), /./, "ReSoLvEd");
ok(false, "should have rejected");
ex){
deepEqual(ex.message, "Missing }
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
})java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.