Closed
Description
I 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?
Metadata
Metadata
Assignees
Labels
No labels