Skip to content

expect.subset() not type-safe #283

@dhardtke

Description

@dhardtke

Hi,

first of all: Thanks a lot for all the work you have put into earl. We are currently evaluating if we will switch from chai to it because the lack of type-safety is really an issue.

We have tons of chai assertions using chai-subset that are written like this:

const items = [
  { _id: 42, foo: 'bar' },
  { _id: 43, foo: 'baz' },
  { _id: 44, lorem: 'ipsum' }
];

expect(items).to.containSubset([
  { _id: 42 },
  { _id: 44 }
])

The same assertion can be written with earl using:

expect(items).toInclude(
  expect.subset({ _id: 42 }),
  expect.subset({ _id: 44 }),
)

However it is not type safe as the following would also compile:

expect(items).toInclude(
  expect.subset({ x: 'y' }),
)

I would expect subset() to only accept Partials or (or deep Partials) of the type of items that are passed to expect().

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