Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Fix return undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jul 12, 2021
1 parent dc10ee9 commit ccc3445
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace degenerator {
const r = function (this: any, ...args: A): Promise<R> {
try {
const p = fn.apply(this, args);
if (typeof p.then === 'function') {
if (typeof p?.then === 'function') {
return p;
}
return Promise.resolve(p);
Expand Down
9 changes: 8 additions & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('degenerator()', () => {
'Expected a "function" to be returned for `foo`, but got "number"'
);
});
it('should be compile if branches', () => {
it('should compile if branches', () => {
function ifA(): string {
if (a()) {
return 'foo';
Expand Down Expand Up @@ -173,5 +173,12 @@ describe('degenerator()', () => {
}
assert.equal(err.message,'process is not defined')
});
it('should allow to return synchronous undefined', () => {
function u() {}
const fn = compile(`${u}`, 'u', ['']);
return fn().then(val => {
assert.strictEqual(val, undefined);
});
});
});
});

0 comments on commit ccc3445

Please sign in to comment.