Node.js testing RESTful API (vows.js?)

后端 未结 3 882
深忆病人
深忆病人 2021-02-15 15:14

I could really do with some advice on testing a RESTful api I created in node.js. There are a plethora of frameworks out there and I am at a loss. My testing knowledge isn\'t go

3条回答
  •  后悔当初
    2021-02-15 15:47

    http://blog.nodejitsu.com/rest-easy-test-any-api-in-nodejs is designed for this very purpose. It's a DSL that sits on top of Vows that streamlines the process of writing out tests using vows.

    Basic test:

    //
    // Here we will configure our tests to use 
    // http://localhost:8080 as the remote address
    // and to always send 'Content-Type': 'application/json'
    //
    suite.use('localhost', 8000)
         .setHeader('Content-Type', 'application/json');
         //
         // A GET Request to /ping
         //   should respond with 200
         //   should respond with { pong: true }
         //
         .get('/ping')
           .expect(200, { pong: true })
         //
         // A POST Request to /ping
         //   should respond with 200
         //   should respond with { dynamic_data: true }
         //
         .post('/ping', { dynamic_data: true })
           .expect(200, { dynamic_data: true })
    

提交回复
热议问题