0.1.1 • Published 7 years ago

supertest-test2doc v0.1.1

Weekly downloads
88
License
MIT
Repository
github
Last release
7 years ago

supertest-test2doc

A supertest extension to make life easier with test2doc.js.

Usage

npm install --save-dev supertest test2doc supertest-test2doc

Simple use const request = require('supertest-test2doc')(require('supertest')) and request(app).with(doc) and then you no longer need to write doc.get/post/put/delete/query/resBody....

E.g.

const doc = require('test2doc')
const request = require('supertest-test2doc')(require('supertest'))
require('should')

// For Koa, you should exports app.listen() or app.callback() in your app entry
const app = require('./my-express-app.js')

after(function () {
  doc.emit('api-documentation.apib') // Or doc.emit('api-documentation.yaml', 'swagger') if you like Swagger
})

doc.group('Products').is(doc => {
  describe('#Products', function () {
    doc.action('Get all products').is(doc => {
      it('should get all products', function () {
        return request(app).with(doc)
          .get('/products')
          .query({
            minPrice: doc.val(10, 'Only products of which price >= this value should be returned').required()
          })
          .expect(200)
          .then(res => {
            res.body.desc('List of all products')
              .should.not.be.empty()
            res.body[0].should.have.properties('id', 'name', 'price')
            res.body[0].price.desc('Price of this product').should.be.a.Number()
          })
      })
    })
  })
})

You can find more examples here.

License

The project is released under MIT License.

0.1.1

7 years ago

0.1.0

7 years ago