test: refactor test-whatwg-webstreams-encoding to be shorter

PR-URL: https://github.com/nodejs/node/pull/54569
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
David Dong 2024-09-19 23:26:02 +08:00 committed by GitHub
parent c8c108f9b0
commit 291d90acbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,32 +45,15 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString();
assert.strictEqual(tds.encoding, 'utf-8');
assert.strictEqual(tds.fatal, false);
assert.strictEqual(tds.ignoreBOM, false);
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, 'encoding', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, 'fatal', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, 'ignoreBOM', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, 'readable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, 'writable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
['encoding', 'fatal', 'ignoreBOM', 'readable', 'writable'].forEach((getter) => {
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, getter, {}), {
name: 'TypeError',
message: /Cannot read private member/,
stack: new RegExp(`at get ${getter}`)
}
);
});
}
{
@ -91,20 +74,13 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString();
]).then(common.mustCall());
assert.strictEqual(tds.encoding, 'utf-8');
assert.throws(
() => Reflect.get(TextEncoderStream.prototype, 'encoding', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextEncoderStream.prototype, 'readable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(TextEncoderStream.prototype, 'writable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
['encoding', 'readable', 'writable'].forEach((getter) => {
assert.throws(
() => Reflect.get(TextDecoderStream.prototype, getter, {}), {
name: 'TypeError',
message: /Cannot read private member/,
stack: new RegExp(`at get ${getter}`)
}
);
});
}