mirror of
https://github.com/tc39/test262.git
synced 2025-07-25 15:04:43 +02:00
Gracefully handle nullish arguments in harness/compareArray
This commit is contained in:
parent
24c6732806
commit
9e75c60028
@ -30,10 +30,12 @@ compareArray.format = function(array) {
|
|||||||
return `[${array.map(String).join(', ')}]`;
|
return `[${array.map(String).join(', ')}]`;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.compareArray = function(actual, expected, message) {
|
assert.compareArray = function(actual, expected, message = '') {
|
||||||
|
assert(actual != null, `First argument shouldn't be nullish. ${message}`);
|
||||||
|
assert(expected != null, `Second argument shouldn't be nullish. ${message}`);
|
||||||
var format = compareArray.format;
|
var format = compareArray.format;
|
||||||
assert(
|
assert(
|
||||||
compareArray(actual, expected),
|
compareArray(actual, expected),
|
||||||
`Expected ${format(actual)} and ${format(expected)} to have the same contents. ${(message || '')}`
|
`Expected ${format(actual)} and ${format(expected)} to have the same contents. ${message}`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
28
test/harness/compare-array-falsy-arguments.js
Normal file
28
test/harness/compare-array-falsy-arguments.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
compareArray gracefully handles nullish arguments.
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function assertThrows(func, errorMessage) {
|
||||||
|
var caught = false;
|
||||||
|
try {
|
||||||
|
func();
|
||||||
|
} catch (error) {
|
||||||
|
caught = true;
|
||||||
|
assert.sameValue(error.constructor, Test262Error);
|
||||||
|
assert.sameValue(error.message, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(caught, `Expected ${func} to throw, but it didn't.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThrows(() => assert.compareArray(), "First argument shouldn't be nullish. ");
|
||||||
|
assertThrows(() => assert.compareArray(null, []), "First argument shouldn't be nullish. ");
|
||||||
|
assertThrows(() => assert.compareArray(null, [], "foo"), "First argument shouldn't be nullish. foo");
|
||||||
|
|
||||||
|
assertThrows(() => assert.compareArray([]), "Second argument shouldn't be nullish. ");
|
||||||
|
assertThrows(() => assert.compareArray([], undefined, "foo"), "Second argument shouldn't be nullish. foo");
|
Loading…
x
Reference in New Issue
Block a user