Giter Site home page Giter Site logo

loopback-testing's Introduction

#loopback-testing

Utilities for testing LoopBack apps

overview

The following helpers are designed to generate [mocha] tests against LoopBack apps.

install

npm install loopback-testing --save-dev

basic usage

Below is a simple LoopBack app.

var loopback = require('loopback');
var app = loopback();
var Product = app.model('product');
Product.attachTo(loopback.memory());

Use the loopback-testing module to generate mocha tests.

var lt = require('loopback-testing');
var assert = require('assert');

describe('/products', function() {
  lt.beforeEach.withApp(app);
  lt.describe.whenCalledRemotely('GET', '/products', function() {
    lt.it.shouldBeAllowed();
    it('should have statusCode 200', function() {
      assert.equal(this.res.statusCode, 200);
    });

    lt.givenModel('product');
    it('should respond with an array of products', function() {
      assert(Array.isArray(this.res.body));
    });
  });
});

building test data

Use TestDataBuilder to build many Model instances in one async call. Specify only properties relevant to your test, the builder will pre-fill remaining required properties with sensible defaults.

var TestDataBuilder = require('loopback-testing').TestDataBuilder;
var ref = TestDataBuilder.ref;

// The context object to hold the created models.
// You can use `this` in mocha test instead.
var context = {};

var ref = TestDataBuilder.ref;
new TestDataBuilder()
  .define('application', Application, {
    pushSettings: { stub: { } }
  })
  .define('device', Device, {
     // use the value of application's id
     // the value is resolved at build time
     appId: ref('application.id'),
     deviceType: 'android'
  })
  .define('notification', Notification)
  .buildTo(context, function(err) {
    // test models are available as
    //   context.application
    //   context.device
    //   context.notification
  });

loopback-testing's People

Contributors

bajtos avatar karlmikko avatar ritch avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.