From e21d784cf8185545638c48881fe52ed2aa47bac0 Mon Sep 17 00:00:00 2001 From: Lauri Piisang Date: Tue, 6 Nov 2018 15:29:11 +0000 Subject: [PATCH] test: add else and error case for TextDecoder add test for tinyurl.com/codeandlearn-encoding-1 add test for tinyurl.com/codeandlearn-encoding-2 PR-URL: https://github.com/nodejs/node/pull/24162 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- .../test-whatwg-encoding-textdecoder-fatal.js | 12 ++++++++++++ test/parallel/test-whatwg-encoding-textdecoder.js | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/test/parallel/test-whatwg-encoding-textdecoder-fatal.js b/test/parallel/test-whatwg-encoding-textdecoder-fatal.js index cfb595e78e6b40..6d0ed1ef842d37 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-fatal.js +++ b/test/parallel/test-whatwg-encoding-textdecoder-fatal.js @@ -91,3 +91,15 @@ bad.forEach((t) => { assert(!new TextDecoder().fatal); assert(new TextDecoder('utf-8', { fatal: true }).fatal); } + +{ + const notArrayBufferViewExamples = [false, {}, 1, '', new Error()]; + notArrayBufferViewExamples.forEach((invalidInputType) => { + common.expectsError(() => { + new TextDecoder(undefined, null).decode(invalidInputType); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + }); + }); +} diff --git a/test/parallel/test-whatwg-encoding-textdecoder.js b/test/parallel/test-whatwg-encoding-textdecoder.js index e87364de1e91f7..10f2c8ea0197e8 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-textdecoder.js @@ -76,6 +76,14 @@ if (common.hasIntl) { }); } +// Test TextDecoder, label undefined, options null +{ + const dec = new TextDecoder(undefined, null); + assert.strictEqual(dec.encoding, 'utf-8'); + assert.strictEqual(dec.fatal, false); + assert.strictEqual(dec.ignoreBOM, false); +} + // Test TextDecoder, UTF-16le { const dec = new TextDecoder('utf-16le');