Giter VIP home page Giter VIP logo

jasmine-testing's Introduction

Jasmine Testing

Rewrite the below console.log test assertions using Jasmine:

// Create a function that converts cents to decimal value
// Function should return undefined when parameter passed is a string
// Function should return undefined when NaN or undefined value is passed as a parameter
// Function should return undefined when parameter is not passed
// Function should convert value from cents to floating point number with 2 decimals
// Function should return a string representation of a number with `$` sign appended at the end

function centsToDecimals(centValue) {
  if (typeof centValue !== 'number' || isNaN(centValue)) return undefined;

  let result = centValue / 100;

  return result.toFixed(2) + "$";
}


// Simple tests

console.warn(' -->  Function should return undefined when parameter passed is a string');
console.log(centsToDecimals('abcdef') === undefined);
console.log(centsToDecimals('1000') === undefined);


console.warn(' -->  Function should return undefined when NaN or undefined value is passed as a parameter');
console.log(centsToDecimals(undefined) === undefined);
console.log(centsToDecimals(NaN) === undefined);

console.warn(' -->  Function should return undefined when parameter is not passed');
console.log(centsToDecimals() === undefined);

console.warn(' -->  Function should convert value from cents to floating point number with 2 decimals');
console.log(centsToDecimals(1000) === "10.00$");
console.log(centsToDecimals(50273) === "502.73$");

console.warn(' -->  Function should return a string representation of a number with `$` sign appended at the end');
console.log(centsToDecimals(0) === "0.00$");

Run The Tests

To run the tests open SpecRunner.html in the browser.

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.