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

Allow regexes in t.like #3309

Open
tommy-mitchell opened this issue Feb 26, 2024 · 2 comments
Open

Allow regexes in t.like #3309

tommy-mitchell opened this issue Feb 26, 2024 · 2 comments
Labels

Comments

@tommy-mitchell
Copy link
Contributor

The message property in t.throws is really ergonomic - it can be a string, RegExp, or even a function. t.like should be just as ergonomic with strings:

const output = foo();

t.like(output, {
  name: 'foo',
  source: /foo comes from/,
});

A motivating example is trying to convert this test from npm-user to use t.like:

const user = await npmUser('sindresorhus');

t.like(user, {
	name: 'Sindre Sorhus',
	avatar: /npm-avatar/,
	email: 'sindresorhus@gmail.com',
});
@novemberborn
Copy link
Member

Currently like is a partial deepEqual, selecting from the actual (first argument) just those properties that exist in the expected (second argument). How would we do that if expected contains a regular expression value?

@Saberian1992

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants