loopback-testing-helpers
v1.0.3
Published
Helpers to test loopback remote methods
Downloads
7
Readme
Loopback remote testing helpers
The purpose of this library is to enable easy unit testing, mimicking the angular SDK behavior. also integrating with supertest library
How to use
Install
$ npm install --save-dev loopback-testing-helpers
Write your tests
var app = require('./server/server');
var h = require('loopback-testing-helpers')(app);
describe('Api testing', function() {
describe('People', function() {
it('find()', function(done) {
h.People.find().expect(200).end(done);
});
it('findOne()', function(done) {
h.People.findOne({filter: {where: {eyes: 'brown'}}})
.expect(200, done);
});
describe('Secured methods', function() {
var user;
before(function(done) {
h.User.login({username: 'me', password: 'secret'})
.expect(200)
.end(function(err, res) {
user = res.body;
done(err);
});
});
it('create()', function(done) {
var person = {
eyes: 'brown',
hair: 'green',
skin: 'blue'
};
h.People.create(person)
.set('Authorization', user.accessToken)
.expect(201)
.end(function(err, res) {
var person = res.body;
expect(person).to.have.property('id');
done(err);
});
});
});
})
})
TODO
- Helpers for handle accessToken
- Write tests
- Add promises?
- no need
res.body
Contributions
feel free to fork this repo, any help is love