Skip to content

Commit 172e552

Browse files
Trottjasnell
authored andcommitted
test: add WPT console-label-conversion test
Add console-label-conversion.any.js from WPT to the test suite. PR-URL: #23340 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0b61f39 commit 172e552

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const { test, assert_true, assert_throws } =
6+
require('../common/wpt');
7+
8+
/* eslint-disable max-len, object-curly-spacing */
9+
10+
/* The following tests should not be modified as they are copied */
11+
/* WPT Refs:
12+
https://github.com/web-platform-tests/wpt/blob/6f0a96ed650935b17b6e5d277889cfbe0ccc103e/console/console-label-conversion.any.js
13+
License: hhttps://github.com/web-platform-tests/wpt/blob/6f0a96ed650935b17b6e5d277889cfbe0ccc103e/LICENSE.md
14+
*/
15+
16+
// https://console.spec.whatwg/org/#counting
17+
// https://console.spec.whatwg/org/#timing
18+
19+
const methods = ['count', 'countReset', 'time', 'timeLog', 'timeEnd'];
20+
21+
for (const method of methods) {
22+
test(() => {
23+
let labelToStringCalled = false;
24+
25+
console[method]({
26+
toString() {
27+
labelToStringCalled = true;
28+
}
29+
});
30+
31+
assert_true(labelToStringCalled, `${method}() must call toString() on label when label is an object`);
32+
}, `console.${method}()'s label gets converted to string via label.toString() when label is an object`);
33+
34+
test(() => {
35+
assert_throws({name: 'Error'}, () => {
36+
console[method]({
37+
toString() {
38+
throw new Error('conversion error');
39+
}
40+
});
41+
}, `${method} must re-throw any exceptions thrown by label.toString() conversion`);
42+
}, `console.${method}() throws exceptions generated by erroneous label.toString() conversion`);
43+
}
44+
45+
/* eslint-enable */

0 commit comments

Comments
 (0)