Skip to content
No description or website provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
LICENSE
README.md
index.js
package.json

README.md

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

You can’t perform that action at this time.