Skip to content

Commit

Permalink
test: split test-whatwg-encoding-textdecoder-fatal.js
Browse files Browse the repository at this point in the history
Split `test-whatwg-encoding-textdecoder-fatal.js` into

- `test-whatwg-encoding-custom-textdecoder-fatal.js` which
  is a customized version of the WPT that tests for Node.js-specific
  error codes.
- `test-whatwg-encoding-custom-textdecoder-invalid-arg` which
  tests `ERR_INVALID_ARG_TYPE`

PR-URL: #25155
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed Jan 1, 2019
1 parent a8f5191 commit deceb26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

// From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-fatal.html
// With the twist that we specifically test for Node.js error codes

const common = require('../common');

Expand Down Expand Up @@ -82,21 +83,10 @@ bad.forEach((t) => {
);
});

// TODO(joyeecheung): remove this when WPT is ported
{
assert('fatal' in new TextDecoder());
assert.strictEqual(typeof new TextDecoder().fatal, 'boolean');
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
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

// This tests that ERR_INVALID_ARG_TYPE are thrown when
// invalid arguments are passed to TextDecoder.

const common = require('../common');

{
const notArrayBufferViewExamples = [false, {}, 1, '', new Error()];
notArrayBufferViewExamples.forEach((invalidInputType) => {
common.expectsError(() => {
new TextDecoder(undefined, null).decode(invalidInputType);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError
});
});
}

0 comments on commit deceb26

Please sign in to comment.