Skip to content

[Bug]: Native fetch Arrays Incorrectly Matched #15025

@popeeyy

Description

@popeeyy

Version

v30.0.0-alpha.3 and v29.7.0

Steps to reproduce

  1. Create a test file with this code
it('matches fetch parsed Array', async () => {
    expect(await (await fetch('https://avatar.roblox.com/v1/users/1/outfits')).json()).toMatchObject({
        data: expect.any(Array),
        filteredCount: expect.any(Number),
        total: expect.any(Number)
    })
})

it('matches manually parsed Array', async () => {
    expect(JSON.parse(await (await fetch('https://avatar.roblox.com/v1/users/1/outfits')).text())).toMatchObject({
        data: expect.any(Array),
        filteredCount: expect.any(Number),
        total: expect.any(Number)
    })
})
  1. Run Jest

Expected behavior

Jest should identify the data property in the response body parsed by fetch as an Array.

Actual behavior

Jest does not identify the data property in the response body as an Array if it is parsed by fetch, only if it is parsed using JSON.parse.

Screenshot 2024-04-12 at 8 37 47 AM Screenshot 2024-04-12 at 8 37 30 AM

Additional context

I am using the latest Node.js LTS version (v20.12.2)

Environment

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.12.2 - /usr/local/bin/node
    npm: 10.5.0 - /usr/local/bin/npm
    pnpm: 7.30.3 - /usr/local/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions