Allow toThrow() matcher to match a regular expression #343

Closed
gregjacobs opened this Issue Mar 16, 2013 · 8 comments

Projects

None yet

5 participants

@gregjacobs

It would be very useful to be able to match the error message of the Error to a regular expression. Ex:

expect( function() {
    throw new Error( "Invalid: xyz" );
} ).toThrow( /Invalid/ );

Probably a fairly simply change. Would just run RegExp.test() on the Error's message.

@infews
Collaborator
infews commented Mar 16, 2013

Seems like a good idea. Want to take a crack at it?

@gregjacobs

Sure, I'll take a look-see.

@gregjacobs

Hmm, just checked out, but unit tests fail?

@OhaiBBQ
OhaiBBQ commented Mar 19, 2013

hey greg, I just checked out locally and can't reproduce that. Any more info?

@sheelc
Collaborator
sheelc commented Apr 7, 2013

I was able to see 2 spec failures on master with grunt execSpecsInNode. The version of lib/jasmine-core/jasmine.js is out of date with the spec files (rake core_spec is unaffected since it seems to run against the non-concatenated js files in src/). A grunt buildDistribution gets everything all consistent and passing.

Perhaps these were the unit test failures that Greg saw? Either way, it seems like the checked in version of jasmine.js needs to be updated?

@infews
Collaborator
infews commented May 27, 2013

closing as this shouldn't be a problem on source. But yes, its not in the built jasmine yet.

@infews infews closed this May 27, 2013
@jsplaine
jsplaine commented Dec 2, 2013
  • 1 put it in the build?
@sheelc
Collaborator
sheelc commented Dec 3, 2013

This feature is in the built distribution and part of the latest rc (v2.0.0.rc5) under 'toThrowError'.

Passing a regex to 'toThrowError' checks that the thrown error message matches the regex. Passing a regex to 'toThrow' will check that what was thrown is an equivalent regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment