Make assertions (such as .exist) callable
See original GitHub issueI am currently writing some tests using the expect-version of chai. And it is going fine, except there is a readability issue.
Take the following code:
expect(someVariable).to.exist;
This is perfectly valid, and will test as expected, since the assertion is done inside the getter .exist
.
But to my eye, there is no action taken here. I would much prefer the line to be:
expect(someVariable).to.exist();
This can be achieved by simply changing the .exist
definition from:
Object.defineProperty(Assertion.prototype, 'exist',
{ get: function () {
this.assert(
null != flag(this, 'object')
, 'expected #{this} to exist'
, 'expected #{this} to not exist'
);
return this;
}
, configurable: true
});
to:
Object.defineProperty(Assertion.prototype, 'exist',
{ get: function () {
this.assert(
null != flag(this, 'object')
, 'expected #{this} to exist'
, 'expected #{this} to not exist'
);
var self = this;
return function() { return self; };
}
, configurable: true
});
The only drawback is that you cannot chain directly on .exist
(like expect(a).to.exist.ok
), but since there is no .and
and the tests does not break after doing the change above, I don’t see that as an issue.
So the question is, is this only an issue in my mind? And should I spend time on making a proper pull request?
Issue Analytics
- State:
- Created 11 years ago
- Reactions:5
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Make assertions (such as .exist) callable · Issue #56 · chaijs/chai
1. An assertion will be a method when parameter(s) are needed, a property when a paramater(s) are not needed. · 2. All assertions...
Read more >callable statement problem - help — oracle-tech
hi i'm using odbc with ms sql server... i get this error when trying to do callablestatement: java.sql.SQLException:
Read more >Package pijamas version ~develop - DUB - The D package registry
Asserts whether a callable object wrapped around the assertion throws an exception of type T. ... void throwing() { throw new Exception("I throw...
Read more >java - Where in the Callable Statement stays ... - Stack Overflow
I'm trying to make a integration test for a method that a call a procedure, the values are coming, but I just want...
Read more >Diff - 66c91e5046..ad5c9b9b07 - chromium/src - Git at Google
+ """Checks to make sure DCHECK_IS_ON() does not skip the parentheses. ... if no browser window exists then create one with no tabs...
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
One problem with this approach is that many editors/linters warns against using expressions as statements. It’s quite useful to not have to disable such settings but sometimes they can only be set per project so one can’t just disable them for tests.
Sure. I’ve just created #407 for that.