EdwardRutz / js-testing-chai

JAVASCRIPT, TDD, Using Chai to write tests for Javascript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript Testing with Chai

Simple Javascript testing Chai.

  • Testing to confirm a movie title is formatted in the proper Title Case.

Dependencies

  • Node.js
  • Chai

Setup and Install

  • Clone repo
  • Install dependencies
  • In terminal, move into the chai-tests directory and run tests on textUtilities.js
node textUtilities.js
  • Chai will show a waiting prompt if all tests pass or an error message


Chai throws an assertion error when the movie title is not in the proper title case.


Chai shows a waiting console prompt when tests are correct

Notes

  • Using Behavior Driven Development (BDD) style with the Chai expect method
  • Chai is a BDD/TDD assertion library for node and the browser. It can pair with any javascript testing framework. ChaiJS.com
  • Writing tests with Chai's expect method

TDD Process

  • The goal is to create a function to evaluate a move title and make sure the words are capitalized
  • First write a test to confirm the movie title is a string. Then write the code and check it with the test
  • Then break the process down into small steps, check one letter, then check one word
  • Write a test to check if the first letter in the word is capitalized
  • Then write a function and a step to capitalize the a letter
  • Then the first letter of a word.
  • Build logic for changing one word then put it into a loop:
    • Split each word in the string
    • Rejoin each word back into the title
  • Review info in tutorial

References

About

JAVASCRIPT, TDD, Using Chai to write tests for Javascript.


Languages

Language:JavaScript 100.0%