Problem with getting text from document when testing vscode extension

5 days ago 8
ARTICLE AD BOX

As my comment suggested, you do need async/await to get the test to run as you expect. Here is the updated code:

suite( 'Extension Test Suite', () => { test( 'Smoke test', async () => { let editor = vscode.window.activeTextEditor; if ( editor !== undefined ) { let testText = `failed`; let expectedResult = `passed`; await editor.edit( editBuilder => { editBuilder.replace( editor.selection.active, testText ); } ).then( ( result ) => { assert.strictEqual( result, true ); // stops here first } ); // stop here second assert.strictEqual( editor.document.getText(), expectedResult, "Text should match" ); } else throw new Error( "Editor is undefined" ); } ); } );

Now the assert.strictEqual( editor.document.getText(), expectedResult, "Text should match" ); line is hit after the edit replace is completed. I do see failed in the file at that point.

The thing I don't understand is that you insert testText ("failed") into the file and then assert that "failed" will equal "passed" ??

Mark's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article