Skip to content

Commit fa9d00c

Browse files
Simon Stoneandrew-coleman
authored andcommitted
Correctly handle null values when executed with a callback (#53)
1 parent 502c2e3 commit fa9d00c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

jsonata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ var jsonata = (function() {
13741374
}
13751375

13761376
if(environment.lookup('__jsonata_async') &&
1377-
(typeof result === 'undefined' || typeof result.then !== 'function')) {
1377+
(typeof result === 'undefined' || result === null || typeof result.then !== 'function')) {
13781378
result = Promise.resolve(result);
13791379
}
13801380
result = yield result;

test/async-function.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,25 @@ describe('Invoke JSONata with callback - errors', function() {
8383
});
8484
});
8585

86+
describe('Invoke JSONata with callback - return values', function() {
87+
it('should handle an undefined value', function() {
88+
var data = { value: undefined };
89+
var expr = jsonata('value');
90+
return expect(jsonataPromise(expr, data)).to.eventually.equal(undefined);
91+
});
92+
it('should handle a null value', function() {
93+
var data = { value: null };
94+
var expr = jsonata('value');
95+
return expect(jsonataPromise(expr, data)).to.eventually.equal(null);
96+
});
97+
it('should handle a value', function() {
98+
var data = { value: 'hello' };
99+
var expr = jsonata('value');
100+
return expect(jsonataPromise(expr, data)).to.eventually.equal('hello');
101+
});
102+
it('should handle a promise', function() {
103+
var data = { value: Promise.resolve('hello') };
104+
var expr = jsonata('value');
105+
return expect(jsonataPromise(expr, data)).to.eventually.equal('hello');
106+
});
107+
});

0 commit comments

Comments
 (0)