Confessions and Confusions of a Freelance Fullstacker.

Ashok Mannolu Arunachalam, How toJestUnit testingNodeJS

How to run jest unit tests with ES6 modules in Node.js

Recently one of my VueJS side projects, I have used jest to do unit testing and I must say I really like the simplicity of it.

More over, it is blazing fast with parrell execution and runs only the changed specs on watch mode.

Jest in NodeJS

In order to start with jest, let's first install it by the following:

$ npm i jest

After the successful installation, configure your package.json as below to run unit specs:

"scripts": {
"test": "jest"

Yes, its that simple! \O/

Jest magic

When we run jest script, it just starts to look for files ending with spec.js from the running directory and starts executing them.

A sample of the unit is below:

describe('App.vue', () => {
it('should render with app banner', () => {
const wrapper = shallowMount(App)
const banner = wrapper.find('.banner')
.toMatch(/iTunes Album Finder/)
/One stop for all your favourite artist's albums/

If you are familiar with jasmine, then this should not be a surprise to you. ^_^

Happy Testing! \O/