mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibJS/Tests: Improve valueToString() output
This regressed recently and would only output a bunch of '[object Foo]', the reason being that String(value) failed in some cases - which is easily fixed by trying that first and using Object.prototype.toString() as a fallback in the case of an exception :^)
This commit is contained in:
parent
844efde54b
commit
63a1275378
1 changed files with 8 additions and 1 deletions
|
@ -51,7 +51,14 @@ class ExpectationError extends Error {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const valueToString = value => Object.prototype.toString.call(value);
|
const valueToString = value => {
|
||||||
|
try {
|
||||||
|
return String(value);
|
||||||
|
} catch {
|
||||||
|
// e.g for objects without a prototype, the above throws.
|
||||||
|
return Object.prototype.toString.call(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Expector {
|
class Expector {
|
||||||
constructor(target, inverted) {
|
constructor(target, inverted) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue