Skip to content

Commit b53a3ea

Browse files
committed
test(define-operation): improve coverage of defineOperation
1 parent 0adaa65 commit b53a3ea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/defineOperation_tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const expect = require('chai').expect;
66
const testMethod = defineOperation(kerberos._testMethod, [
77
{ name: 'string', type: 'string' },
88
{ name: 'shouldError', type: 'boolean', default: false },
9+
{ name: 'optionalString', type: 'string', required: false },
910
{ name: 'callback', type: 'function', required: false }
1011
]);
1112

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

18+
it('should support defaults', function(done) {
19+
expect(() => testMethod('testing')).to.not.throw();
20+
testMethod('testing', true, err => {
21+
expect(err).to.exist;
22+
done();
23+
});
24+
});
25+
1726
it('should return a promise if no callback is provided', function() {
1827
const promise = testMethod('llamas', false);
1928
expect(promise).to.be.instanceOf(Promise);
2029
});
30+
31+
it('should use a callback if provided', function(done) {
32+
testMethod('testing', false, 'optional', (err, result) => {
33+
expect(err).to.not.exist;
34+
expect(result).to.equal('optional');
35+
36+
testMethod('testing', true, 'optional', (err, result) => {
37+
expect(err).to.exist;
38+
expect(result).to.not.exist;
39+
40+
done();
41+
});
42+
});
43+
});
2144
});

0 commit comments

Comments
 (0)