Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

Convention for writing end-to-end tests


There are certain guidelines to be followed when writing the end-to-end tests:


Test cases should be written considering the end users and considering the real
scenario
Multiple test cases should be created for different scenarios
The requirements should be gathered for all the software or applications that are
involved
For each requirement, gather as many conditions or scenarios as possible
Write separate test cases for each scenario

Technologies we will be using


Here are some of the packages that we will be working with to write the tests for our


application:


Mocha: A JavaScript test framework to write unit testing (https:/​/​mochajs.​org/
)
Chai: An assertion library for the Node.js framework (http:/​/​chaijs.​com/​)
Sinon: sinon is for test spies, stubs, and mocks (http:/​/​sinonjs.​org/​)
Nightwatch: A JavaScript library for writing end-to-end tests (http:/​/
nightwatchjs.​org/​)
Karma: karma is the test runner for JavaScript (https:/​/​karma-​runner.​github.
io/​2.​0/​index.​html)

We will discuss each of these technologies as we go along.


Introducing Mocha


Let's create a separate working directory to learn to write tests. Create a folder called


test_js and switch to the test_js directory:


> mkdir test_js
> cd test_js
Free download pdf