Bug 1754015 - Assert.jsm should throw when comparing a NaN number, r=Gijs.

Differential Revision: https://phabricator.services.mozilla.com/D138041
This commit is contained in:
Florian Quèze 2022-02-16 09:56:34 +00:00
parent d538838400
commit ee0f63bdfc
2 changed files with 16 additions and 2 deletions

View File

@ -515,8 +515,8 @@ proto.rejects = function(promise, expected, message) {
};
function compareNumbers(expression, lhs, rhs, message, operator) {
let lhsIsNumber = typeof lhs == "number";
let rhsIsNumber = typeof rhs == "number";
let lhsIsNumber = typeof lhs == "number" && !Number.isNaN(lhs);
let rhsIsNumber = typeof rhs == "number" && !Number.isNaN(rhs);
if (lhsIsNumber && rhsIsNumber) {
this.report(expression, lhs, rhs, message, operator);

View File

@ -409,6 +409,20 @@ function run_test() {
}
assert.equal(message, "AssertionError: 2 <= 1");
try {
assert.greater(NaN, 0);
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 'NaN' is not a number");
try {
assert.greater(0, NaN);
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 'NaN' is not a number");
/* ---- stringMatches ---- */
assert.stringMatches("hello world", /llo\s/);
assert.stringMatches("hello world", "llo\\s");