Skip to content

Commit

Permalink
test(define-operation): improve coverage of defineOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Nov 27, 2018
1 parent 0adaa65 commit b53a3ea
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/defineOperation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const expect = require('chai').expect;
const testMethod = defineOperation(kerberos._testMethod, [
{ name: 'string', type: 'string' },
{ name: 'shouldError', type: 'boolean', default: false },
{ name: 'optionalString', type: 'string', required: false },
{ name: 'callback', type: 'function', required: false }
]);

Expand All @@ -14,8 +15,30 @@ describe('defineOperation', () => {
expect(() => testMethod(42)).to.throw(/Invalid type for parameter/);
});

it('should support defaults', function(done) {
expect(() => testMethod('testing')).to.not.throw();
testMethod('testing', true, err => {
expect(err).to.exist;
done();
});
});

it('should return a promise if no callback is provided', function() {
const promise = testMethod('llamas', false);
expect(promise).to.be.instanceOf(Promise);
});

it('should use a callback if provided', function(done) {
testMethod('testing', false, 'optional', (err, result) => {
expect(err).to.not.exist;
expect(result).to.equal('optional');

testMethod('testing', true, 'optional', (err, result) => {
expect(err).to.exist;
expect(result).to.not.exist;

done();
});
});
});
});

0 comments on commit b53a3ea

Please sign in to comment.