Skip to content

Uint8.buffer is not instance of ArrayBuffer when environment is jsdom #3976

@charlie632

Description

@charlie632

Describe the bug

Checking the uint8.buffer instance fails when checking with the global ArrayBuffer class.

/**
 * @vitest-environment jsdom
 */

describe(() => {
  it('arraybuffer', async () => {
    const uint8 = new Uint8Array([1]);
    expect(uint8.constructor.name).toBe('Uint8Array');
    expect(uint8 instanceof Uint8Array).toBeTruthy();
    expect(ArrayBuffer.isView(uint8)).toBeTruthy();
    expect(uint8.buffer instanceof ArrayBuffer).toBeTruthy();
  });
});

When using @vitest-environment jsdom.

Using node works well, tho.

This scenario should work in the browser as seen here:
image

Using:

"vitest@0.28.4"

"jsdom@22.1.0"

Reproduction

/**
 * @vitest-environment jsdom
 */

describe(() => {
  it('arraybuffer', async () => {
    const uint8 = new Uint8Array([1]);
    expect(uint8.constructor.name).toBe('Uint8Array');
    expect(uint8 instanceof Uint8Array).toBeTruthy();
    expect(ArrayBuffer.isView(uint8)).toBeTruthy();
    expect(uint8.buffer instanceof ArrayBuffer).toBeTruthy();
  });
});

System Info

System:
    OS: macOS 13.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.18 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 1.19.0 - ~/Workspace/platform/client-applications/node_modules/.bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 115.0.5790.170
    Chrome Canary: 118.0.5953.0
    Edge: 115.0.1901.200
    Firefox: 116.0.2
    Safari: 16.6

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions