Skip to content

Commit d2e4392

Browse files
authored
chore(async-rewriter): add tests for template strs and typeof (foo) (#2414)
1 parent bc5cfd6 commit d2e4392

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/async-rewriter2/src/async-writer-babel.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@ describe('AsyncWriter', function () {
370370
expect(await ret).to.equal('bar');
371371
});
372372

373+
it('can implicitly await inside of template literals', async function () {
374+
implicitlyAsyncFn.resolves('foobar');
375+
const ret = runTranspiledCode(
376+
'(() => { return `>>${implicitlyAsyncFn()}<<`; })()'
377+
);
378+
expect(ret.constructor.name).to.equal('Promise');
379+
expect(ret[Symbol.for('@@mongosh.syntheticPromise')]).to.equal(true);
380+
expect(await ret).to.equal('>>foobar<<');
381+
});
382+
373383
it('can implicitly await inside of branches', async function () {
374384
implicitlyAsyncFn.resolves({ foo: 'bar' });
375385
const ret = runTranspiledCode(`
@@ -476,6 +486,10 @@ describe('AsyncWriter', function () {
476486
expect(runTranspiledCode('typeof nonexistent')).to.equal('undefined');
477487
});
478488

489+
it('supports typeof for un-defined variables in parentheses', function () {
490+
expect(runTranspiledCode('typeof ((nonexistent))')).to.equal('undefined');
491+
});
492+
479493
it('supports typeof for implicitly awaited function calls', async function () {
480494
implicitlyAsyncFn.resolves(0);
481495
expect(await runTranspiledCode('typeof implicitlyAsyncFn()')).to.equal(

0 commit comments

Comments
 (0)