GithubHelp home page GithubHelp logo

.throw broken? about chai HOT 6 CLOSED

chaijs avatar chaijs commented on May 4, 2024
.throw broken?

from chai.

Comments (6)

logicalparadox avatar logicalparadox commented on May 4, 2024

As it currently stands, I'm afraid your misusing throw. I can see use cases that match your scenario so, first off, we can use this ticket as a feature request for your scenarios and improve upon the docs.

Until then, the reason your approach isn't working is that chai doesn't support string error matchers. Just instance or regexp.

Supported:

 // checks for any kind of error
expect(badFn).to.throw();

 // will pass for instanceof the error type specified
expect(badFn).to.throw(Error);
expect(badFn).to.throw(ReferenceError);

// check to see if error.message will pass regex test
expect(badFn).to.throw(/match regex to message/); 

As i see it, the 3 following cases are not yet covered.

expect(badFn).to.throw('string message matcher');
expect(badFn).to.throw(ErrorConstructor, 'string message matcher');
expect(badFn).to.throw(ErrorConstructor, /match regex to message/);

Will try to get to them tonight and improve upon the documentation. Keep you posted, and thanks for the report.

from chai.

michaelsbradleyjr avatar michaelsbradleyjr commented on May 4, 2024

Okay, thanks.

Actually, your explanation reminded me that expect.js also supports regex matching but not string matching for error messages. But in the process of switching to chai, I drifted back into semantics proper to jasmine (which supports string matching for error messages).

Anyway, I can use regex for now and will look forward to the expanded features. Thanks for your hard work on chai. I really enjoy using it in combination with mocha and sinon.

I have an idea for a plugin also, but I need another day or so to tighten up the standalone library which would form the basis for it. I can file another issue to start that conversation (when the time is ripe), but that leads me to ask if the chai folks hang out in a particular IRC channel on Freenode?

from chai.

logicalparadox avatar logicalparadox commented on May 4, 2024

I added this to the 0.5.x milestone which I will be working on this weekend.

I sometimes hang out in the #node.js channel, I am "logicalparadox". I also just created a Google Group: https://groups.google.com/group/chaijs that might be a better forum for non-issue questions and help. I will start promoting that shortly.

Also, your waitsFor plugin looks like it would be an awesome addition to the chai toolbelt. Let me know if you have questions as you look to add support.

from chai.

michaelsbradleyjr avatar michaelsbradleyjr commented on May 4, 2024

Awesome. I just posted a message in the new google group, thanks for setting it up. :-)

Also, I created a new Freenode channel, which is intended for (relatively) focused discussions on JS testing: #letstest.js. I don't know if it will get off the ground, but hopefully some chai fans will chime in.

from chai.

logicalparadox avatar logicalparadox commented on May 4, 2024

The throw feature has been implemented in 0.5.0.

Also, made a note of the the Google Group and IRC channel in the README and on the doc site.

Let me know if you have further issues.

from chai.

michaelsbradleyjr avatar michaelsbradleyjr commented on May 4, 2024

Awesome, thanks for the hard work.

from chai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.