Skip to content

Commit

Permalink
fix: correctly resolve buffer on typed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 24, 2023
1 parent 7dac059 commit fd1447c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/vitest/src/integrations/env/jsdom-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ const LIVING_KEYS = [
'Headers',
'AbortController',
'AbortSignal',

'Uint8Array',
'Uint16Array',
'Uint32Array',
'Uint8ClampedArray',
'Int8Array',
'Int16Array',
'Int32Array',
'Float32Array',
'Float64Array',
'ArrayBuffer',
'DOMRectReadOnly',
'DOMRect',
Expand Down
19 changes: 19 additions & 0 deletions test/core/test/dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,25 @@ it('uses jsdom ArrayBuffer', async () => {
expect(arraybuffer.constructor === ArrayBuffer).toBeTruthy()
})

it.each([
'Uint8Array',
'Uint16Array',
'Uint32Array',
'Uint8ClampedArray',
'Int16Array',
'Int32Array',
'Int8Array',
'Float32Array',
'Float64Array',
] as const)('%s has buffer as ArrayBuffer', async (constructorName) => {
const Constructor = globalThis[constructorName]
const typedArray = new Constructor([1])
expect(typedArray.constructor.name).toBe(constructorName)
expect(typedArray instanceof Constructor).toBeTruthy()
expect(ArrayBuffer.isView(typedArray)).toBeTruthy()
expect(typedArray.buffer instanceof ArrayBuffer).toBeTruthy()
})

it('doesn\'t throw, if listening for error', () => {
const spy = vi.fn((e: Event) => e.preventDefault())
window.addEventListener('error', spy)
Expand Down

0 comments on commit fd1447c

Please sign in to comment.