Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

55 Commits

Repository files navigation

#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.

varloopback=require('loopback');varapp=loopback();varProduct=app.model('product');Product.attachTo(loopback.memory());

Use the loopback-testing module to generate mocha tests.

varlt=require('loopback-testing');varassert=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.

varTestDataBuilder=require('loopback-testing').TestDataBuilder;varref=TestDataBuilder.ref;// The context object to hold the created models.// You can use `this` in mocha test instead.varcontext={};varref=TestDataBuilder.ref;newTestDataBuilder().define('application',Application,{pushSettings: {stub: {}}}).define('device',Device,{// use the value of application's id// the value is resolved at build timeappId: ref('application.id'),deviceType: 'android'}).define('notification',Notification).buildTo(context,function(err){// test models are available as// context.application// context.device// context.notification});

About

Utilities for testing LoopBack apps

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors