adopted-ember-addons / ember-cli-flash

Simple, highly configurable flash messages for ember-cli
https://www.npmjs.com/package/ember-cli-flash
MIT License
355 stars 113 forks source link

Documentation is wrong about acceptance tests #216

Closed begedin closed 7 years ago

begedin commented 7 years ago

Correct me if I'm wrong, but this seems to be the case on my environment:

[] == false // evaluates as true
[] == true // evaluates as false
![] // returns false (!)
!![] // returns true
[] ? 'foo' : 'bar' // returns "bar"

The assert.ok helper uses !!result to determine truthiness, so it will always pass in the example, since wind will either return an empty or a populated array.

sbatson5 commented 7 years ago

Hey @begedin 👋

You're definitely right. Here is a quick twiddle demonstrating this in an acceptance test: https://ember-twiddle.com/367f2485e4d8e6ceaa31c0a9932eb2e3?openFiles=tests.acceptance.my-acceptance-test.js%2C

Would love a review if you think this works!

begedin commented 7 years ago

The twiddle works, but for the purpose of the documentation, I would go even more explicit and do something like

assert.ok(find('.alert.alert-info').length === 0)

or

assert.equal(find('.alert.alert-info').length, 0)
sbatson5 commented 7 years ago

@begedin in that case, we would be asserting that the length is not 0. If it is 0, it will return falsy--all other values with be true. I kind of like that we are testing for its presence and not for a specific number.