Skip to content

not.throwError with regexp matching should only fail if an error is actually thrown#79

Open
christianalfoni wants to merge 3 commits into
Automattic:masterfrom
christianalfoni:master
Open

not.throwError with regexp matching should only fail if an error is actually thrown#79
christianalfoni wants to merge 3 commits into
Automattic:masterfrom
christianalfoni:master

Conversation

@christianalfoni

Copy link
Copy Markdown

We built our own error constructor for arguments passed to a function, ArgumentsError.

When we test our code we get a problem with expect(fn).to.not.throwError(/ArgumentsError/)

This is what happens:

  • If an error is thrown, but is of a different type: OK (as expected)
  • If an error is thrown, and is an ArgumentsError: FAILS (as expected)
  • If no errors are thrown: FAILS (not expected)

I have added a verification that there actually is an error thrown before reverting the NOT flag, as the NOT flag should only be reverted on actual throws, as I see it. No errors, not.to.throwError should pass even with a regexp matcher :-)

@truongsinh

Copy link
Copy Markdown

Can you please add a test case for this bug?

@christianalfoni

Copy link
Copy Markdown
Author

Aha, sorry, added test now :-)

Do I have to create a new pull request or can you just grab it?

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