Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
6 tasks done
charlie632 opened this issue Aug 17, 2023 · 2 comments · Fixed by #3998
Closed
6 tasks done

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

charlie632 opened this issue Aug 17, 2023 · 2 comments · Fixed by #3998

Comments

@charlie632
Copy link

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

@charlie632
Copy link
Author

Please, let me know if this is a JSDOM specific issue, if so, I can report it there.

@charlie632
Copy link
Author

Thanks @sheremet-va!

@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants