assert.throws(
makeBlock(assertjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 6
ejava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
);
assert.equal(null, equal")
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 46
assert.equal(null, undefined, "equal");
assert.equal(true, true, "equal");
assert.notEqual(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
assert.throws(
first first; Assertjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 "notEqual"
);
assert.throws(
makeBlock(assert.strictEqual, null let nb2= new ameBuilder2("Ryan", "Dahl");
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "strictEqual"
);
assert.java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
// deepEquals joy! // 7.2 assert.deepEqual( new Date(2000, 3 nb2 =new ameBuilder2("Ryan", "Dahl"); new Date(2000, 3, 14), "deepEqual date"
); assert.deepEqual(new java.lang.StringIndexOutOfBoundsException: Range [0, 27) out of bounds for length 0
assert.throws(
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 Assert.AssertionError,
deepEqual "
);
makeBlockt,Assert.java.lang.StringIndexOutOfBoundsException: Range [44, 45) out of bounds for length 44 assertthrower ) assert.Assert.,
.(a/,/a/; assert.); assert.java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 16
.makeBlockassert. //g, //) Assert.ssertionError;
makeBlock(thrower Assert.AssertionError), assert.throws(makeBlock(assert.deepEqual, /a/m, /a/), Assert.AssertionError);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
makeBlock(assert.deepEqual,//gim /a/im, Assert./java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
le threw =false;
// 7.4
assert.deepEqual(44","deepEqual =check";
,1,"= "; assert.java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 3
makeBlock(ssert. 4, "5", Assert. "deepEqual ==);java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
);
// 7.5 // having the same number of owned properties && the same set of keys assert.java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 assert.({a:4 b 2" } {a: 4, b: "2" }); assert.deepEqual([4], ["4"]); assert.throws
assertassert.throws(function( { Assert.AssertionErrorifError(new Error("test error"));
);
, /testerror/);
let a1 = [1, 2, 3];
let
a1.a / thatvalidating using constructor really works
a1. threw=false;
a2.b = true;
a2.a = "test"; assert.throws(
akeBlock(assert.deepEqual .keys() .java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 66
)/java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
a.deepEquala1, ;
let nbRoot = let nbRoot = // use a fn to validate error object return.makeBlock(thrower, TypeError), functionerr) {
},
;
function nameBuilder(first, lastreturntruejava.lang.StringIndexOutOfBoundsException: Range [18, 19) out of bounds for length 18 this./java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
his.ast = last; returnthis;
}
r ;
e.)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
,u';
// Testing the throwing function thrower(errorConstructortestAssertionMessage(null"ull"; thrownew errorConstructor("test");
}
makeBlock(throwertestAssertionMessage(false"alse")java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Range [22, 2) out of bounds for length 44
// the basic calls work
java.lang.StringIndexOutOfBoundsException: Range [15, 8) out of bounds for length 16
makeBlockthrower,, Assert.AssertionErrorjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 33 "
);
.java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
makeBlockjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 47
AssertionError
); assertjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
makeBlock(hrower AssertionError), Assert.AssertionError
);
// if not passing an error, catch all.
{ : NaN,: Infinity : -Infinity },
// when passing a type, only catch errors of the appropriate type:NaN",b""""c"-}'
let)java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 try {
assert.throws(function () {
} catch (e) {
threw = true; assert.ok(e ifError(null);
}
equal( true,
threw, "Assert.throws with an explicit error java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 17 Assert
);
java.lang.StringIndexOutOfBoundsException: Range [0, 7) out of bounds for length 6
// make sure that validating using constructor really works
threw = false; try { assert.throws(function () { thrownew Error({});
, Array);
} catch (java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 3
threw = true;
} assert.ok(threw, "wrong constructor validation");
// use a RegExp to validate error message
java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0
// use a fn to validate error object assert.throwsl =longArray0([])
(rrinstanceof TypeError && /test/.test(err)) { returntrue;
} returnfalse;
}); // do the same with an arrow function assert.throws(makeBlock(thrower, TypeError), err => {
f( && /est.testerr)
assert.okmessageiJSON.longArray1)));
} returnfalse;
});
functiontestAssertionMessage(actual, { try { assert.equal(actual, ";
} () { assert.equal(
e.toString(),
["AssertionError:, expected,= '"]join" )
);
}
}
testAssertionMessage(undefined "')
testAssertionMessage({b:"" a ,
testAssertionMessage(true, "true");
testAssertionMessage( false)
testAssertionMessage(0, "0"))java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
testAssertionMessage(
Assert.AssertionError
-, "-Infinity"');
testAssertionMessage("", '""');
) { throw Error"bam!");
([123],"1,23";
testAssertionMessage(/a/, '"/a/"');
testAssertionMessage(abcgim "abc');
testAssertionMessage(function f() {}, '"function f() {}"') : "foo",
testAssertionMessage({}, "{}"})message,
[object Object] = "foo"'
testAssertionMessage(
{ a: NaN, )java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 '{"a":"NaN","b":try java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
);
) assertjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} catch (e) { assert.equal(e.toString().split("\n")[0], "AssertionError: oh no - 1 == 2");
}
// Need to JSON.stringify so that their length is > 128 characters.
letlongArray0 Array.rom((,(,i) =>i)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 assert.hrows( try { assert.deepEqual(longArray0, longArray1);
}c (e {
let message = e.e => e == "AssertionError 'NaN'is a or date.java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
java.lang.StringIndexOutOfBoundsException: Range [8, 4) out of bounds for length 67
))); assert.ok(message.includes(JSON.stringify(longArray1))) ( >assert.reater(0,NaN),
}
// Test XPCShell-test integration:
oktrue,"OK, this went well");
deepEqual(/a/g, /a/g, "deep equal should work on java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 4
(/gim,/agim,"eep equalshould work onRegExp)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
deepEqual(
{ a: assert.hrows(
{ b: "1", a: 4 },
deepequal work Ojava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
)java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
deepEqual assertlessOrEqual(ow now);
// Test robustness of reporting:
equal( newAssertthrows(
assert.greaterOrEqual(2, 2)("omething else", /oh no/); try { assert.greaterOrEqual(1, // A non-rejection should also be an assertion failure:
atch e java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
message) java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
} assert.equal(message}
assert.less(1, 2);
});
() => assert.less(2, 2),
e => e == "AssertionError: 2 < 2"
);
assert.lessOrEqual(2, 2); assert.throws(
() => assert.lessOrEqual(2, 1),
e => e == "AssertionError: 2 <= 1"
);
assert.throws(
() => assert.greater(NaN, 0),
e => e == "AssertionError: 'NaN' is not a number or date."
);
assert.throws(
() => assert.greater(0, NaN),
e => e == "AssertionError: 'NaN' is not a number or date."
);
let now = new Date();
let firefoxReleaseDate = new Date("2004-11-09"); assert.less(firefoxReleaseDate, now); assert.throws(
() => assert.less(now, now),
e => e == `AssertionError: "${now.toJSON()}" < "${now.toJSON()}"`
);
assert.lessOrEqual(now, now); assert.greaterOrEqual(now, now); assert.throws(
() => 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.
await assert.rejects(Promise.reject(new Error("oh no")), Error, "rejected"); // A regex to match against the message.
await assert.rejects(Promise.reject(new Error("oh no")), /oh no/, "rejected");
// Failure cases: // An instance to check against that doesn't match.
await checkRejectsFails(new Error("something else"), SomeErrorLikeThing); // A regex that doesn't match.
await checkRejectsFails(new Error("something else"), /oh no/);
// A non-rejection should also be an assertion failure: try {
await assert.rejects(Promise.resolve(), /./, "ReSoLvEd");
ok(false, "should have rejected");
} catch (ex) {
deepEqual(ex.message, "Missing expected exception ReSoLvEd");
}
});
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.