Giter Site home page Giter Site logo

testing-javascript's Introduction

Introduction to Unit Testing in JavaScript

Installation

First, clone this repository. Once, you have it on your computer, navigate to the directory in the terminal and run the following command:

npm install

Starting Up

Run the following from your terminal:

npm start

Getting Started

We'll be modifying two files as we complete these exercises:

  • implentation.js
  • test.js

Just to verify that everything works, there should be a first example in place.

// implementation.js
function square(n) {
  return n * n;
}
// test.js
describe('square', function () {

  it('returns the square of a number', function () {
    assert.equal(square(2), 4);
  });

});

Together

Let's write a few simple cases together. We'll revisit our old friends from last week.

  • addTwo()
  • multiply()
  • subtract()
  • multiply()
  • divide()

Your Turn: FizzBuzz

FizzBuzz is a classic programming program that a lot of programmers apparently can't do.

We're going to write a function called fizzBuzz() that will behave as follows with the each rule taking precendence over all previous rules:

  • If we pass it a number, it will return that number.
  • If we pass a number that is a multiple of 3, it will return 'Fizz'.
  • If we pass it a number that is a multiple of 5, it will return 'Buzz'.
  • If we pass it a number that is a multiple of both 3 and 5, it will return 'FizzBuzz'.

testing-javascript's People

Contributors

stevekinney avatar allpurposename avatar

Watchers

Chaz-Mykl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.