Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
soundasleep opened this Issue · 4 comments

4 participants

@soundasleep

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

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.

@keithamus keithamus referenced this issue in domenic/sinon-chai
Closed

Add lint friendly assertions #48

@joshperry

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

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
Owner

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

@keithamus keithamus closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.