Consistency with returning new Assertion instead of this
See original GitHub issueA change was made a few months ago to return a new Assertion object with flags copied over instead of returning this
. References: #562 #642
However, it looks like there are still some spots where this
is returned. The only one I’ve actually tested so far is overwriteProperty.
For example:
const {expect, use} = require("chai");
use(function (chai, utils) {
utils.overwriteProperty(chai.Assertion.prototype, "and", function (_super) {
return function blah () {
_super.call(this);
};
});
});
it("but", () => {
expect([1, 2, 3]).to.be.an.but.length.below(1000) // Passes
});
it("and", () => {
expect([1, 2, 3]).to.be.an.and.length.below(1000) // Fails
});
As expected, the second assertion fails with error: “TypeError: expect(…).to.be.an.and.length.below is not a function” because the overwritten and
is returning the function that was originally returned by the chainable method an
instead of returning a new Assertion.
Other places where this might be a problem (but I haven’t tested):
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
typescript-eslint/consistent-type-assertions.md at main - GitHub
This rule aims to standardize the use of type assertion style across the codebase. Keeping to one syntax consistently helps with code readability....
Read more >Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java programming language that enables you to test your assumptions about your program. For example, if...
Read more >Writing Good Assertions - Manning Publications
Consider, for example, an addToInventory function which adds items to the store's inventory and returns the new quantity available.
Read more >What does the Java assert keyword do, and when should it be ...
Java can do this through assertions: // Calculates the sum of a (int) + b (int) and returns the result (int). int sum(int...
Read more >Assertion messages in tests - Enterprise Craftsmanship
If you feel that the test isn't clear without assertion messages, try to refactor it instead. In the long run, it's easier to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vieiralucas This PR #642 has more details about it. I think this post explains the reason behind this whole thing, I highly recommend anyone involved with this issue to read that.
YES SIR! 😸
I’m still reading through all the issues and PR’s involved in this issue. I think I’ll be able to submit a PR addressing thi later today.