assert-request: a promise based replacement for supertest to test an HTTP server

9 comments · 90% upvoted · source · other discussions

comments

halkeye

Is this your module? Can you explain the benefits of this over https://www.npmjs.com/package/supertest-as-promised

This looks like it at least changes all the function names so its not a drop in replacement.

PlasmaPower [OP]

Sure thing!

It's not a drop in replacement because:

  • It wouldn't be drop in anyways now that it uses promises
  • As previously mentioned, .expect doesn't work very well

Edit: and yes, this is my module. My NPM username is the same :).

halkeye

sweet. we've seen some weird and wacky things with supertest + nock, so it might be worth looking into replacement.

Do you have support for negation? I guess in the body() function it could assert if not contain? I really get frustrated with trying to do supertest expect not contains.

PlasmaPower [OP]

For expecting if something doesn't exist, you could use .body(body => !body.includes('text')) or the like.

I've thought about negating something in general, but I'm not sure of a good way to do it. I could abstract the mixins to a general formula that could be easily negated, but I'm not sure that would be worth it. I'll think about it.

PlasmaPower [OP]

If you have any suggestions for a negation API, please let me know. Remember that arrow functions can't have this.

Edit: .not.body(...) might work. I'll look into it.

Edit 2: I have some ideas for a general mixin assertion API. It would not be a breaking change. I should be able to implement them tomorrow.

halkeye

With the body function and chai-as-promised I think your example is awesome.

.body(body => body.should.not.contain('text'))    
PlasmaPower [OP]

Glad that works! Thinking about it some more, I don't think I'll need the negation API, if a specific assertion needs it I'll add it individually.

chrisdefourire

your module made me want to write a few regression tests for my new project :) Thanks ! looks nicer than supertest (which I used in the past)

chrisdefourire

with node 0.12, requires mocha --harmony and Object.prototype.assign = require('object.assign') (npm install --save-dev object.assign of course)...

makes for the most readable tests ever (in coffee-script)