# loopback-supertest-models

> ## Setup

Latest version **3.5.0** (published 2018-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install loopback-supertest-models
pnpm add loopback-supertest-models
yarn add loopback-supertest-models
bun add loopback-supertest-models
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.5.0 |
| Published | 2018-05-18 |
| First published | 2017-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 47.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Nathan Bolam |
| Maintainers | bolamn |

## Links

- npm: https://www.npmjs.com/package/loopback-supertest-models
- Repository: https://github.com/BoLaMN/loopback-supertest-models
- Homepage: https://github.com/BoLaMN/loopback-supertest-models#readme
- Issues: https://github.com/BoLaMN/loopback-supertest-models/issues
- npm.io page: https://npm.io/package/loopback-supertest-models

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^2.4.1
- [supertest](https://npm.io/package/supertest.md) ^3.0.0

## Recent versions

- 3.5.0 (latest) — 2018-05-18
- 3.0.0 — 2017-07-12
- 2.2.0 — 2017-07-12
- 2.1.7 — 2017-06-30
- 2.1.6 — 2017-06-30
- 2.1.5 — 2017-06-30
- 2.1.1 — 2017-06-24
- 2.1.0 — 2017-06-24
- 2.0.5 — 2017-06-24
- 2.0.1 — 2017-06-22
- 2.0.0 — 2017-06-22
- 1.0.1 — 2017-06-15
- 1.0.0 — 2017-06-15

## README

# loopback-supertest-models

## Setup

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

## Example

using supertest's `end` function 

```javascript
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

```javascript
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 

```javascript
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

---
_Source: https://npm.io/package/loopback-supertest-models · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
