Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow .true() assertion to use an optional message #272

Closed
soundasleep opened this issue Jun 17, 2014 · 4 comments
Closed

Allow .true() assertion to use an optional message #272

soundasleep opened this issue Jun 17, 2014 · 4 comments

Comments

@soundasleep
Copy link

Expected: expect(false).to.be.true("message") should display "message".

Actual: It displays "AssertionError: expected false to be true".

Providing useful error messages is supported for other assertions (.a, .equal, .above etc), can this not also be supported for the core .true and .false assertions?

@charlierudolph
Copy link

At the moment no properties (ok, true, false, null, undefined, exists, empty, arguments) take in a message. This is because these assertions are properties and not methods. You assert with expect(false).to.be.true instead of expect(false).to.eql(true, 'message')

Would need true to become a method for this to be possible.

@joshperry
Copy link
Contributor

@keithamus I've been thinking about how this would be implemented while still supporting throw on property access when there may or may not be a function call at the end of the chain. I can't think of a way to look ahead in the chain.

// Throw on function call so that we can show message
expect(false).to.be.true('Universal constants have broken down');

// Still support throwing on property access
expect(false).to.be.true;

// Support a message at the end of the chain with a property throw midway?
expect(false).to.be.true.and.not.false('Universal constants have broken down');

@keithamus
Copy link
Member

Yeah, I'm inclined to agree. The only way I can think of is to have a runtime flag which disables the assertion in the getter and pushes it into the function.

@keithamus
Copy link
Member

Closing this as we had to revert #297. Unfortunately this doesn't look possible in the near to distant future for Chai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants