API testing with javascript

589 views
Skip to first unread message

drew dimanlig

unread,
Mar 9, 2016, 12:48:26 PM3/9/16
to API Craft
I plan on porting a Java based API test suite to javascript and am looking for framework suggestions.  I've been looking at using Frisby or Chakram.  Any advice on choosing a framework?

Thanks

Kevin Swiber

unread,
Mar 9, 2016, 1:32:31 PM3/9/16
to API Craft
I've used both Mocha and Cucumber.  You can see some examples here: https://github.com/kevinswiber/siren-api-testing

I use revolt (https://www.npmjs.com/package/revolt), a reactive HTTP client, to chain together HTTP workflows in a nice, clean fashion.

I've also used supertest (https://www.npmjs.com/package/supertest), and the assertion method chaining is quite nice.

There are a million options in the JavaScript world, but these are current favorites.

Good luck!

Cheers,

Kevin

On Wed, Mar 9, 2016 at 9:48 AM drew dimanlig <drew.d...@gmail.com> wrote:
I plan on porting a Java based API test suite to javascript and am looking for framework suggestions.  I've been looking at using Frisby or Chakram.  Any advice on choosing a framework?

Thanks

--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Visit this group at https://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Carl Sutherland

unread,
Mar 10, 2016, 2:44:09 PM3/10/16
to API Craft
I also use Mocha with supertest and plain old request (https://www.npmjs.com/package/request).

Chai is what I use for assertions, and they've got a plugin for HTTP: http://chaijs.com/plugins/chai-http/ which I haven't used.

Mocha + request-promise + chai has worked out great for us!

Best,
-Carl

Michael Tiller

unread,
Mar 11, 2016, 5:04:20 PM3/11/16
to api-...@googlegroups.com
I was just working on some API testing.  I used mocha and I started with supertest, but switched to Axios.  It doesn't include the testing primitives directly in the library (it is more like superagent), but chai provides enough functionality.  Big advantage of Axios is that it is promised base from the start.

--
Mike

Przemek Wesołek

unread,
Mar 25, 2016, 7:02:02 AM3/25/16
to API Craft
Some time ago I used superagent, Mocha and Chai, with some custom helpers (today I'd give a look at chai-http). Something like this (CoffeeScript):

class ExpectResponseWrapper
    constructor
: (req) ->
       
@req = req
       
@expectations = []

    add
: (exp) ->
       
@expectations.push exp
       
this

    success
: -> @add (res) ->
        expect
(res.status, 'HTTP status code is 2xx (Success)').to.be.within(200,299)

    status
: (code) -> @add (res) ->
        expect
(res.status, "HTTP status code is #{code}").to.equal(code)

    json
: -> @add (res) ->
        expect
(res.type, "Content type is application/json").to.equal('application/json')

    andDo
: (fn) -> @add fn

   
end: (done) ->
       
@req.end (err, res) =>
           
if err
               
if done? then done err else throw err
               
return
           
try
                exp res
for exp in @expectations
           
catch e
               
if done? then done e else throw e
               
return
           
done?()

expectResponse
= (req) -> new ExpectResponseWrapper(req)



And the testing looked like:

        it "can be created", (done) =>
            req
= request.post @url
               
.set 'Content-Type', 'application/json'
               
.send @body
            expectResponse
(req)
               
.status(201)
               
.andDo (res) =>
                   
@obj = res.body
                   
@loc = res.headers['location']
               
.end(done)

drew dimanlig

unread,
Apr 12, 2016, 6:01:14 PM4/12/16
to API Craft
Thanks for all of your suggestions!

drew dimanlig

unread,
Apr 13, 2016, 4:49:32 PM4/13/16
to API Craft
Actually, have any of you had to test an api call that does a multipart upload using a json object instead of a file?

I'm trying to test an api call that does a multipart upload using a json object instead of a file. Here is an example of the json that gets passed in a parameter named jsonpayload:

{ "videos": [{ "remote_url": "https://s3.amazonaws.com/testing/test_videos/video.mp4" }], "text": "groups", "author": { "alias": "testing", "token": "1456167795" }, "groups": ["custom"] ,"tags":["tagged"]}

Mayank Gupta

unread,
May 2, 2016, 6:21:50 AM5/2/16
to API Craft
Hi Drew,

Are you using Chakram for RESTful API testing and multipart upload is also worked fine with this?

-Thanks
Mayank Gupta

Drew Dimanlig

unread,
May 6, 2016, 1:28:37 PM5/6/16
to api-...@googlegroups.com
I haven't tried the multipart upload with Chakram, yet.

--
You received this message because you are subscribed to a topic in the Google Groups "API Craft" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/api-craft/xoXufIVFPtY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to api-craft+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages