From a32cb805a2f8cc144354fa606923db2452ba1a0d Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 4 Feb 2020 17:34:12 -0800 Subject: [PATCH] Adding some basic tests for auto insert of await on completions --- .../src/test/completions.test.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/extensions/typescript-language-features/src/test/completions.test.ts b/extensions/typescript-language-features/src/test/completions.test.ts index 196b034402f..644871101d0 100644 --- a/extensions/typescript-language-features/src/test/completions.test.ts +++ b/extensions/typescript-language-features/src/test/completions.test.ts @@ -569,6 +569,82 @@ suite('TypeScript Completions', () => { `Config: ${config}`); }); }); + + test('Accepting a completion for async property in `insert` mode should insert and add await', async () => { + await updateConfig({ [Config.insertMode]: 'insert' }); + + await createTestEditor(testDocumentUri, + `class A {`, + ` xyz = Promise.resolve({ 'abc': 1 });`, + ` async foo() {`, + ` this.xyz.ab$0c`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class A {`, + ` xyz = Promise.resolve({ 'abc': 1 });`, + ` async foo() {`, + ` (await this.xyz).abcc`, + ` }`, + `}`, + )); + }); + + test('Accepting a completion for async property in `replace` mode should replace and add await', async () => { + await updateConfig({ [Config.insertMode]: 'replace' }); + + await createTestEditor(testDocumentUri, + `class A {`, + ` xyz = Promise.resolve({ 'abc': 1 });`, + ` async foo() {`, + ` this.xyz.ab$0c`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class A {`, + ` xyz = Promise.resolve({ 'abc': 1 });`, + ` async foo() {`, + ` (await this.xyz).abc`, + ` }`, + `}`, + )); + }); + + test.skip('Accepting a completion for async string property should add await plus brackets', async () => { + await enumerateConfig(Config.insertMode, insertModes, async config => { + await createTestEditor(testDocumentUri, + `class A {`, + ` xyz = Promise.resolve({ 'ab c': 1 });`, + ` async foo() {`, + ` this.xyz.ab$0`, + ` }`, + `}`, + ); + + const document = await acceptFirstSuggestion(testDocumentUri, _disposables); + assert.strictEqual( + document.getText(), + joinLines( + `class A {`, + ` xyz = Promise.resolve({ 'abc': 1 });`, + ` async foo() {`, + ` (await this.xyz)["ab c"]`, + ` }`, + `}`, + ), + `Config: ${config}`); + }); + }); }); async function enumerateConfig(configKey: string, values: readonly string[], f: (message: string) => Promise): Promise {