Comments (16)
that is what i'm leaning towards
think it makes sense to have native support for things like toThrow
on a promise, etc
from chai.
An innate problem with adding promises to core is that all existing assertions synchronously throw, and there is no very clear signal as to what would then turn that into an asynchronous throw. chai-as-promised adds the eventually
chainable property, which we could add but the await
keyword is something that developers are much more likely to be aware of.
One way we could go about this change is to make all assertions return a Promise, but that's a big breaking change (though arguably one that gives us future flexibility for all kinds of async stuff). Another solution could be to extensively document how one would unpack promises within the existing assertions (which typically looks like expect(await ...)
, but the far bigger problem today exists with how to properly handle rejections which involves some code gymnastics.
from chai.
FWIW, my typical use-case for chai-as-promised (using mocha) is:
return expect(testClass.testFunction(args)).to.eventually.be.rejectedWith(Error);
from chai.
i recall in some other test libraries, some smarts were done to change the return type
e.g.
expect(someSyncThing).to.equal(10);
await expect(someAsyncThing).to.equal(10);
and basically have a conditional return:
function equal(expectation: unknown): T extends PromiseLike<unknown> ? Promise<void> : void;
but that may make my fancy types im doing in the typescript branch a bit more difficult 😬
since i'm not sure we can do a type guard return of a promise
from chai.
Related Issues (20)
- 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
- SyntaxError: Invalid or unexpected token HOT 1
- [email protected] syntax error in assertion.js:69 HOT 2
- NPM README and GitHub README don't match
- @types/chai seems not to be adapted to version 5.0.0 HOT 9
- Documentation revamp HOT 3
- please provide commonjs exports again HOT 5
- Migrating to Chai 5.0 in browser
- use() function only returns plugin first time HOT 1
- assert.throws() does not work correctly in node/vm spawned context HOT 5
- TypeError: Unknown file extension ".ts" with Chai 5.0.0 and later 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.