diff --git a/closure/goog/labs/mock/mock.js b/closure/goog/labs/mock/mock.js index cd3062dfd2..f6c5508bd3 100644 --- a/closure/goog/labs/mock/mock.js +++ b/closure/goog/labs/mock/mock.js @@ -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(''); diff --git a/closure/goog/labs/mock/mock_test.js b/closure/goog/labs/mock/mock_test.js index 5228844726..0ab496f036 100644 --- a/closure/goog/labs/mock/mock_test.js +++ b/closure/goog/labs/mock/mock_test.js @@ -1322,6 +1322,28 @@ testSuite({ assertEquals('{"x":}', 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 = {};