Skip to content

Commit c06237a

Browse files
committed
fix: update test
1 parent 5cfa127 commit c06237a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test/jest-tests/polyfill.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ describe('polyfill', () => {
8787
// We will set the "binaryType" and then send/receive the "data" from the datachannel in each test, and then compare them.
8888
// For example, the first line will send a "Hello" string after setting binaryType to "arraybuffer".
8989
const testMessages = [
90-
{ binaryType: 'arraybuffer', data: new TextEncoder().encode('Hello').buffer },
90+
{ binaryType: 'arraybuffer', data: 'Hello' },
9191
{ binaryType: 'arraybuffer', data: createBinaryTestData() },
9292
{ binaryType: 'arraybuffer', data: createBinaryTestData(new ArrayBuffer(100)) },
9393
{ binaryType: 'arraybuffer', data: createBinaryTestData(new ArrayBuffer(100), 50) },
94+
{ binaryType: 'arraybuffer', data: createBinaryTestData(new ArrayBuffer(100), 50) },
95+
{ binaryType: 'blob', data: 'Hello' },
9496
{ binaryType: 'blob', data: new Blob([createBinaryTestData()]) },
9597
];
9698

@@ -100,18 +102,23 @@ describe('polyfill', () => {
100102
let currentIndex: number = -1;
101103

102104
// We run this function to analyze the data just after receiving it from the datachannel.
103-
async function analyzeData(idx: number, data: Blob | ArrayBuffer): Promise<boolean> {
105+
async function analyzeData(idx: number, data: Blob | ArrayBuffer | string): Promise<boolean> {
104106
switch (idx) {
105107
case 0: // binaryType is not used here because data is a string ("Hello").
106-
return new TextDecoder().decode(data as ArrayBuffer) === 'Hello';
108+
return data === 'Hello';
107109
case 1: // binaryType is "arraybuffer" and data is expected to be an ArrayBuffer.
108110
return analyzeBinaryTestData(data as ArrayBufferLike);
109111
case 2: // binaryType is "arraybuffer" and data is expected from a view on a larger ArrayBuffer
110112
return analyzeBinaryTestData(data as ArrayBufferLike);
111113
case 3: // binaryType is "arraybuffer" and data was created from a view on a larger ArrayBuffer with an offset
112114
return analyzeBinaryTestData(data as ArrayBufferLike);
113-
case 4: // binaryType is "blob" and data is expected to be a Blob.
115+
case 4: // binaryType is "arraybuffer" and data was created from a view on a larger ArrayBuffer with an offset
116+
return analyzeBinaryTestData(data as ArrayBufferLike);
117+
case 5: // binaryType is "blob" and data is expected to be a string ("Hello").
118+
return data === 'Hello'
119+
case 6: // binaryType is "blob" and data is expected to be a Blob.
114120
return analyzeBinaryTestData(await (data as Blob).arrayBuffer());
121+
115122
}
116123
return false;
117124
}
@@ -168,12 +175,7 @@ describe('polyfill', () => {
168175
}
169176

170177
// Send the test message
171-
// workaround for https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1973
172-
if (current.data instanceof ArrayBuffer || current.data instanceof Uint8Array) {
173-
dc1.send(current.data);
174-
} else if (current.data instanceof Blob) {
175-
dc1.send(current.data);
176-
}
178+
dc1.send(current.data);
177179
}
178180

179181
// Set Callbacks

0 commit comments

Comments
 (0)