enzymejs / chai-enzyme

Chai.js assertions and convenience functions for testing React Components with enzyme
MIT License
787 stars 72 forks source link

Add optional message argument to all function assertions #186

Open jakubgs opened 7 years ago

jakubgs commented 7 years ago

Regular function assertions in Chai have an optional msg argument, for example:

http://chaijs.com/api/bdd/#method_include

But the chai-enzyme functions do not have it. I consider adding messages at the end of the assert much more readable than in the expect() function, so most of my tests use that form. With chai-enzyme I have to mix two styles now since I cannot supply a msg to something like to.contain.text().

keithamus commented 7 years ago

Going to slide in here with some questions unrelated to the issue here;

I consider adding messages at the end of the assert much more readable than in the expect() function

How do you consider adding custom messages more readable? What do you provide to the message parameter that the default messaging doesn't give you? (Asking because we'd like to improve messaging in chai, but would like feedback from users).

jrnail23 commented 7 years ago

I'll chip in and say that a custom message argument allows you to describe why you're making an assertion. e.g.,

expect(yourElement)
 .to.contain.text('hello', 'because it would be impolite not to say hello')
keithamus commented 7 years ago

@jrnail23 thanks for that, and that is indeed a fine use case. FWIW we wont be removing the message feature - and we very much encourage people to use it for use cases like the above, I was questioning because I want to ensure that without the message, Chai gives users the best clue as to what is going wrong (even if that doesnt tell them why); and so if there is anything we can do to improve the default messaging, we would like to.