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

Documentation error #902

Closed
jpike88 opened this issue Jan 15, 2017 · 4 comments
Closed

Documentation error #902

jpike88 opened this issue Jan 15, 2017 · 4 comments

Comments

@jpike88
Copy link

jpike88 commented Jan 15, 2017

.property(name, [value])

@param { String } name
@param { Mixed } value (optional)
@param { String } message _optional_

... so can I attach a message, or can't I? I seem to be having trouble getting a message to appear so that's probably a no?

@meeber
Copy link
Contributor

meeber commented Jan 15, 2017

Short answer: Yes, you can attach a message. Documentation needs to be updated.

Note that you can set a custom message in one of two ways, however the second way has a gotcha, so I recommend the first way:

var myBreakfast = {sausage: 3, eggs: 2, toast: 2};

// First way: Put custom message as 2nd parameter to `expect`:
expect(myBreakfast, "NO BACON!!!").to.have.property("bacon");
expect(myBreakfast, "NOT ENOUGH TOAST!!!").to.have.property("toast", 5);

// Second way: Put custom message as 3rd parameter to `property`:
expect(myBreakfast).to.have.property("toast", 5, "NOT ENOUGH TOAST!!!");
expect(myBreakfast).to.have.property("bacon", undefined, "NO BACON!!!");
// Gotcha in last test: Asserts if `myBreakfast` has a property `bacon` that's equal to `undefined`... prolly not what is wanted

Tested the above in both Chai 3.5 and the master branch. In both cases, the custom error was present. However, be aware that your test runner may modify the error message after catching it and prior to displaying it. For example, Mocha exhibits different behavior depending on whether or not the showDiff flag is set to true. When showDiff is true, it strips away the default error message and leaves only the custom message. When showDiff is false, it prepends the custom message to the default error message.

@jpike88
Copy link
Author

jpike88 commented Jan 15, 2017

I'm not sure if this is related but I also had to include this line to get the message to show (and this is using the first way of custom message insertion:

chai.config.includeStack = true;

@meeber
Copy link
Contributor

meeber commented Jan 15, 2017

Sounds like a separate issue. Do you have a public repo or standalone example I can look at?

@meeber
Copy link
Contributor

meeber commented Jan 16, 2017

Just noting here that I'm updating the docs related to this.

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

No branches or pull requests

2 participants