Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Format symbols and bigints when creating mock verification error mess…
Browse files Browse the repository at this point in the history
…ages.

RELNOTES: n/a
PiperOrigin-RevId: 575901895
Change-Id: Icf8bca3ca01c124302327034d3d692ee77235d98
  • Loading branch information
12wrigja authored and copybara-github committed Oct 23, 2023
1 parent 9fc3388 commit b704457
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions closure/goog/labs/mock/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ goog.labs.mock.formatValue_ = function(obj, opt_id) {
output.push('NULL');
} else if (typeof obj === 'string') {
output.push('"' + indentMultiline(obj) + '"');
} else if (typeof obj === 'symbol') {
output.push(obj.toString());
} else if (typeof obj === 'bigint') {
output.push(obj.toString(10) + 'n');
} else if (typeof obj === 'function') {
const funcName = goog.labs.mock.getFunctionName_(obj);
output.push('<function ' + funcName + '>');
Expand Down
22 changes: 22 additions & 0 deletions closure/goog/labs/mock/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,28 @@ testSuite({
assertEquals('{"x":<function y>}', mock.formatValue_(obj, false /* id */));
},

/** @suppress {visibility} suppression added to enable type checking */
testFormatSymbols() {
if (typeof window['Symbol'] !== 'function') {
return; // skip browsers without symbols
}
if (Symbol().toString() !== 'Symbol()') {
// skip testing in environments with a likely-polyfilled symbol,
// as their Symbol wouldn't have the right typeof value.
return;
}
assertEquals('Symbol()', mock.formatValue_(Symbol()));
assertEquals('Symbol(foobar)', mock.formatValue_(Symbol('foobar')));
},

/** @suppress {visibility} suppression added to enable type checking */
testFormatBigInts() {
if (typeof window['BigInt'] !== 'function') {
return; // skip browsers without bigints
}
assertEquals('30n', mock.formatValue_(BigInt(30)));
},

testGetUid() {
const obj1 = {};
const obj2 = {};
Expand Down

0 comments on commit b704457

Please sign in to comment.