loopback-supertest-models

3.5.0 • Public • Published

loopback-supertest-models

Setup

  var app = require('./server/server.js');
  var models = require('loopback-supertest-models')(app);

Example

using supertest's end function

describe('GET /api/pokemon', function() {
  it('respond with pokemon', function(done) {
    return models.Pokemon
      .find()
      .expect(200)
      .end(function(err, res) {
        if (err) return done(err);
        done();
      });
  });
});

You can also use promises

describe('GET /api/pokemon/?filter={"name": "pikachu"}', function() {
  it('respond with pikachu', function() {
    return models.Pokemon
      .find({ "name": "pikachu"})
      .expect(200)
      .then(response => {
          assert(response.body.name, 'pikachu')
      })
  });
});

Spy

Spy on when a remote method is called

describe('GET /api/pokemon/?filter={"name": "pikachu"}', function() {
  it('respond with pikachu', function() {
    models.Pokemon.on('find', function(ctx) {
      console.log('on', ctx.filter);
    })
    models.Pokemon.once('find', function(ctx) {
      console.log('once', ctx.filter);
    })
    return models.Pokemon
      .find()
      .expect(200)
      .end(function(err, res) {
        if (err) return done(err);
        done();
      });
  });
});

License: MIT

/loopback-supertest-models/

    Package Sidebar

    Install

    npm i loopback-supertest-models

    Weekly Downloads

    58

    Version

    3.5.0

    License

    MIT

    Unpacked Size

    48.3 kB

    Total Files

    26

    Last publish

    Collaborators

    • bolamn