From bd43ef845ff15e43ed13461fdcb32c67e9e854cc 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 be37f5097c504e..aa945b61b10e72 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-fatal.js +++ b/test/parallel/test-whatwg-encoding-textdecoder-fatal.js @@ -88,3 +88,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 37fbe12757134e..6d1db2ec33faad 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-textdecoder.js @@ -75,6 +75,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');