question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consistency with returning new Assertion instead of this

See original GitHub issue

A 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:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lucasfcostacommented, Sep 13, 2016

@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.

0reactions
vieiralucascommented, Sep 13, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found