Debugging javascript running in Chrome using VSCode

Installation steps:

  • Install mocha NPM module
  •         npm install
            npm install mocha chai --save-dev
            sudo npm install -g mocha
          
  • Install Debugger for Chrome plugin in VSCode
  • Copy the node_modules/mocha folder to your public (or public/lib) folder
  • Copy the node_modules/chai folder to your public (or public/lib) folder
  • Include mocha in the page you want to debug
  •         <html>
              <head>
                <link rel="stylesheet" href="lib/mocha/mocha.css">
              </head>
              <body>
                <script src="lib/mocha/mocha.js"></script>
                <script src="lib/chai/chai.js"></script>
                <script>mocha.setup('bdd')</script>
                <div id="mocha">
                </div>
                <script>
                  mocha.run();
                </script>
              </body>
            </html>
          

You can use chai to run unit tests in NodeJS application by including chai and using mocha to run tests

    # Include this in the script you need to debug
    var chai = require('chai')
  

References:


Nexti SA PTY LTD
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.