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 customMessage to be a function that returns message #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Coridyn
Copy link
Contributor

@Coridyn Coridyn commented Dec 9, 2022

What

Feature: allow the customMessage parameter to be passed a function as well as a string

// Original (and still supported)
expect(value, `custom message string`).toBe(actual);

// New: allow a function that returns the message
expect(value, () => (`custom message from function`)).toBe(actual);

Why

This allows the generation of customMessage to be lazy - i.e. the message will only be generated if the expectation failed.

If the message generation is expensive to do then the cost is only incurred when the test failed.

This also makes the customMessage API more consistent with Jest v27+ that requires the matcher.message property to be a function.

Housekeeping

  • Unit tests
  • Documentation is up to date
  • No additional lint warnings

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

Successfully merging this pull request may close these issues.

1 participant