Skip to content

toHaveBeenCalledWith objectContaining issue after patch update 26.6.1 #10716

Closed
@scagood

Description

@scagood

🐛 Bug Report

Tests that contain Buffers in expect.objectContaining calls started failing after a patch version update.

To Reproduce

A private repo received a dependabot PR for the following update: Bump jest from 26.6.0 to 26.6.1

Previously this test would have passed:

test('issue demo', async () => {
    const func = jest.fn();

    func({ test: Buffer.from('test'), some: 'thing' });

    expect(func).toHaveBeenCalledWith(
        expect.objectContaining({ test: Buffer.from('test') }),
    );
});

That test now throws:

   TypeError: Cannot set property parent of [object Object] which has only a getter

     4 |     func({ test: Buffer.from('test'), some: 'thing' });
     5 |
   > 6 |     expect(func).toHaveBeenCalledWith(
       |                  ^
     7 |         expect.objectContaining({ test: Buffer.from('test') }),
     8 |     );
     9 | });

     at Object.<anonymous> (buffer-issue.test.js:6:18)

Expected behavior

Tests to not start failing after a patch update 😅

envinfo

Before:

 $ npx envinfo --preset jest
npx: installed 1 in 0.642s

  System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
    CPU: (24) x64 AMD Ryzen Threadripper 2920X 12-Core Processor
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    jest: ^26.5.3 => 26.6.0 

After:

 $ npx envinfo --preset jest
npx: installed 1 in 0.681s

  System:
    OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
    CPU: (24) x64 AMD Ryzen Threadripper 2920X 12-Core Processor
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
  npmPackages:
    jest: ^26.5.3 => 26.6.1 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions