Comments (6)
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.
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.
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.
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.
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.
Awesome, thanks for the hard work.
from chai.
Related Issues (20)
- chai.version field is incorrect HOT 8
- Potential Security Vulnerabilities Detected in Package
- Mention existence of `5.x.x` branch and `v5.0.0-alpha.0` in README HOT 2
- `chai.should()` break error reporting in `node:test` on node `18.17.0`
- 5.0.0-alpha.1 was published as "latest" npm dist-tag HOT 2
- strictEqual / deepStrictEqual behave differently on numbers
- Vulnerability in chai Module HOT 2
- Fix get-func-name HOT 3
- Update dependency on `get-func-name` to at least 2.0.1 to fix CVE HOT 5
- Buffer is not recognized as an object HOT 1
- Officia type definitions for 5.x? HOT 6
- Package subpath './register-should' is not defined by "exports" in node_modules/chai/package.json for node 18.14.0 HOT 1
- ERR_REQUIRE_ESM in v5 HOT 41
- v5 vs chai-as-promised HOT 1
- [v5] `assert.isFunction()` fails with async function HOT 4
- v5 - `Unknown file extension ".ts"` when running with mocha HOT 11
- mutating chai exports no longer works in v5 HOT 22
- Add support for Promise HOT 10
- SyntaxError: Invalid or unexpected token HOT 1
- [email protected] syntax error in assertion.js:69 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai.