Skip to content

A simple project to showcase Unit Tests in JavaScript using Mocha/Chai and Stubs

Notifications You must be signed in to change notification settings

irfanalinoor/javascript-unit-tests-mocha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Unit Testing

Overview

  • This is a simple project to showcase Unit Tests in JavaScript using Mocha/Chai and Stubs
  • Skills: Unit Testing using Stub
  • Languages: JavaScript
  • SCM: Git
  • Build/Dependency Management: Mocha/npm/sinon
  • Assertion Lib: Chai, Expect, Should
  • CI/CD: CircleCI CircleCI

Setup

Unit Tests

Unit Test for UserController Class
When ISOLATED (Stubbed)
  ✓ Verify Keys of 'getAll' JSON Output - Stubbed
  ✓ Verify 'Users' is an Array in 'getAll' JSON Output - Stubbed
  ✓ Verify 'id' is NUMBER in 'getAll' JSON Output - Stubbed
  ✓ Verify 'username' is STRING in 'getAll' JSON Output - Stubbed
  ✓ Verify 'email' is STRING in 'getAll' JSON Output - Stubbed 

Unit Test for UserService Class
When ISOLATED (Stubbed)
  ✓ Verify Keys of 'getAll' JSON Output - Stubbed
  ✓ Verify 'Users' is an Array in 'getAll' JSON Output - Stubbed
  ✓ Verify 'id' is NUMBER in 'getAll' JSON Output - Stubbed
  ✓ Verify 'username' is STRING in 'getAll' JSON Output - Stubbed
  ✓ Verify 'email' is STRING in 'getAll' JSON Output - Stubbed

Continuous Integration

  • CircleCI - Config.yml

      version: 2
      jobs:
          build:
              working_directory: ~/javascript-unit-tests-mocha
          docker:
              - image: circleci/node:8.0
              - image: mongo:3.4.4
          steps:
              - run:
                  name: "Checking NodeJs + NPM Version"
                  command: |
                  node --version
                  npm --version
              - checkout
              - restore_cache:
                  key: dependency-cache-{{ checksum "package.json" }}
              - run:
                  name: Install NPM Packages
                  command: 'sudo npm install'
              - run:
                  name: NPM Start
                  command: 'npm start'
              - run:
                  name: Run Unit Tests
                  command: 'npm test'
    

About

A simple project to showcase Unit Tests in JavaScript using Mocha/Chai and Stubs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published