view page source - page history - about editing

Revision History: The Problems with Chai

This is revision 553 of the page The Problems with Chai, as it appeared on Mon, 16 Jun 2014 21:54:05 -0700.
Javascript - EmberJS - Testing

Chai is a pretty reasonable testing framework. But there are some key problems that make it much harder than it should be to test.

Very few methods provide an optional message

Both of these assertions will fail with "is not a function". This means the only message you will get back is expected true to be false and expected undefined to be defined. How helpful.

I've created to hopefully resolve this.

define and it cannot have parameterised tests

define 'my thing', ->
  for i in [0..6]
    it 'tests ' + i, ->

This won't work. I haven't found a way to do parameterised tests yet.

Chaining your own properties is way too hard

It's easy enough to define a basic assertion, for example expect(foo)

But if you want to also support expect(foo), then you have to go through a huge amount of work to store these properties through the assertion chains or something.

All assertions are defined in terms of the expect() object

That means you cannot (easily) have a new assertion like expect(".class"), because we need to define the ".present" w.r.t. the ".class" string, and not what would eventually be a $() selector.

That also means that you can not have an easy-to-understand message for the presence (or not) of elements, because the only context that you have available is the tested object.

(In our project, we could not use the jquery module because it interfered with EmberJS.)
Categories: Testing | Chai

view page source - what links to here? - page history - top
Last edited by jevon jevon 57 months ago