From 291d90acbc746d39d2cece18715ce428c4eb6858 Mon Sep 17 00:00:00 2001 From: David Dong Date: Thu, 19 Sep 2024 23:26:02 +0800 Subject: [PATCH] test: refactor test-whatwg-webstreams-encoding to be shorter PR-URL: https://github.com/nodejs/node/pull/54569 Reviewed-By: James M Snell Reviewed-By: Richard Lau --- .../test-whatwg-webstreams-encoding.js | 60 ++++++------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/test/parallel/test-whatwg-webstreams-encoding.js b/test/parallel/test-whatwg-webstreams-encoding.js index b2b18df73bf1fe..24d9bce7cc5212 100644 --- a/test/parallel/test-whatwg-webstreams-encoding.js +++ b/test/parallel/test-whatwg-webstreams-encoding.js @@ -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}`) + } + ); + }); }