Extension For Writing Mocha Tests In Visual Studio Code

Introduction

In this article, we will discuss how to add a useful visual studio code extension that will speed up in writing test cases.

This extension will be helpful for automation Testers who write tests using mocha.

In order to add the extension to the visual studio code click on the Extension icon in Visual Studio Code.

ES6 Mocha Snippets extension

Search ES6 mocha snippets.

ES6 Mocha Snippets extension

Click the E6 mocha snippet extension

Install the extension by clicking the install button.

ES6 Mocha Snippets extension

It will take few minutes to install

Once installed, in your test automation project create a test file.

Now just type the keyword describe and hit enter

ES6 Mocha Snippets extension

The describe block will get auto-populated, user needs to just provide the test suite name

ES6 Mocha Snippets extension

Inside the describe block, type it keyword and hit

ES6 Mocha Snippets extension

The it block will get auto-populated, user needs to just provide the test case name

ES6 Mocha Snippets extension

We can also auto-populate a describe and it block together by typing describe and using the arrow button to select the describe and it block which appears in the suggestion

ES6 Mocha Snippets extension

In the same way, we can also auto-populate the following hooks in your spec files 

  • before
  • beforeEach
  • after
  • afterEach

We can set context for your tests as well by typing and selecting the respective suggestion which is provided by the extension

  • context
  • context with it block 

Hope this extension will be useful for testers who work in frameworks like Cypress, WebdriverIO, and Playwright. This extension will be very helpful for Automation Testers who are learning and implementing Javascript Test automation frameworks(Cypress, WebdriverIO, playwright)

Summary

In this article, I discussed how we can add Visual Studio Code extension(ES6 Mocha Snippets) which speeds up the process of writing mocha test cases.

Thank you, Happy learning.....


Similar Articles