frisby
Version:
Frisby.js v2.0: REST API Endpoint Testing built on Jasmine
75 lines (58 loc) • 2.01 kB
JavaScript
;
const frisby = require('../src/frisby');
const Joi = frisby.Joi;
const mocks = require('./fixtures/http_mocks');
const testHost = 'http://api.example.com';
describe('expect(\'json\', <path>, <value>)', function() {
describe('json', function() {
it('should get single array object at known position', function(doneFn) {
mocks.use(['getUsers']);
frisby.fetch(testHost + '/users')
.expect('json', 'data.0', {
id: 1,
email: 'joe.schmoe@example.com'
})
.done(doneFn);
});
it('should get single array object at known position and test for single value', function(doneFn) {
mocks.use(['getUsers']);
frisby.fetch(testHost + '/users')
.expect('json', 'data.0.id', 1)
.done(doneFn);
});
it('should test one of the values in an array', function(doneFn) {
mocks.use(['getUsers']);
frisby.fetch(testHost + '/users')
.expect('json', 'data.?', {
id: 1,
email: 'joe.schmoe@example.com'
})
.done(doneFn);
});
// @TODO: Cannot do this off of a question mark yet...
// it('should test one of the values in an array for a single field', function(doneFn) {
// mocks.use(['getUsers']);
//
// frisby.fetch(testHost + '/users')
// .expect('json', 'data.?.email', 'joe.schmoe@example.com')
// .done(doneFn);
// });
});
describe('jsonTypes', function() {
it('should test every object in an array', function(doneFn) {
mocks.use(['getUsers']);
frisby.fetch(testHost + '/users')
.expect('jsonTypes', 'data.*', {
id: Joi.number(),
email: Joi.string().email()
})
.done(doneFn);
});
it('should test every object in an array for a single value', function(doneFn) {
mocks.use(['getUsers']);
frisby.fetch(testHost + '/users')
.expect('jsonTypes', 'data.*.id', Joi.number())
.done(doneFn);
});
});
});