Skip to content

Regression regarding not.toHaveProperty() and non-object input #7942

@ulrichb

Description

@ulrichb

💥 Regression Report

.not.toHaveProperty() doesn't work with non-object "actual" values, instead it throws TypeError: Cannot use 'in' operator.

Last working version

Worked up to version: 23.6.0

Stopped working in version: 24.1.0

To Reproduce

expect({ someObj: true }).not.toHaveProperty("isError", true); // Works

// Fails with "Cannot use 'in' operator to search for 'isError' in true" since Jest 24
expect(true).not.toHaveProperty("isError", true);

// Fails with "Cannot use 'in' operator to search for 'isError' in string" since Jest 24
expect("string").not.toHaveProperty("isError", true); // Fails since Jest 24

Expected behavior

No failure in the snippet above.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions