Skip to content

fix: Function contract error messages are now respected at match time - #1398

Merged
TimothyJones merged 2 commits into
case-contract-testing:mainfrom
JamesBurnsCanva:20260827-fix-error-function-result-message-matching
Aug 28, 2026
Merged

fix: Function contract error messages are now respected at match time#1398
TimothyJones merged 2 commits into
case-contract-testing:mainfrom
JamesBurnsCanva:20260827-fix-error-function-result-message-matching

Conversation

@JamesBurnsCanva

Copy link
Copy Markdown
Contributor

Fixes the issue described in #1397.

  • properly makes validate check message when message is present, instead of checking errorClassName a second time
  • makes check check message when message is present, instead of ignoring it
  • adds tests

…matcher on thrown-error interactions - Co-Authored-By: Claude <noreply@anthropic.com>
… validate() - Co-Authored-By: Claude <noreply@anthropic.com>

@TimothyJones TimothyJones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour is actually by design, let's discuss on the linked issue. I've left a couple of comments, but no need to address them until we've determined whether it should match on messages.

const messageResult = await matchContext.descendAndCheck(
matcher.message,
addLocation(`message`, matchContext),
'message' in actual ? actual['message'] : undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant, you can just pass actual['message']

actual: unknown,
): Promise<MatchResult> =>
Promise.resolve().then(() => {
Promise.resolve().then(async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this with chaining rather than by changing a 200 line function to be async. You can see how the http matcher does this, or follow the pattern used in the validate function.

At that point it might be simpler to separate out the expecting failure and expecting success into functions for readability.

@TimothyJones TimothyJones changed the title chore: Fix function error result matching for message field fix: Message field for errors in function contracts is no longer ignored Aug 28, 2026
@TimothyJones TimothyJones changed the title fix: Message field for errors in function contracts is no longer ignored fix: Function contract error messages are now respected at match time Aug 28, 2026
@TimothyJones
TimothyJones merged commit 8bffcc0 into case-contract-testing:main Aug 28, 2026
14 checks passed
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.

2 participants