Giter VIP home page Giter VIP logo

purify's Introduction

Purify

  • Working in pairs
  • Fork and clone repo
  • Run npm install to install jest
  • Create a test folder where your tests will live
  • Implement tests for each function. Provide at least 2 test cases for each function
  • Rewrite functions to become pure functions. Use tests to verify the inputs to each function remain unchanged by the execution of each function
  • Replace instance of var with constor let as appropriate
  • Replace for loops etc with relevant array methods
  • Submit pull request with completed code

When testing that inputs have not changed, it's best to produce similar objects for input and expectedInput. This is because, if we run the following code

test('Ensure purity', function() {
  const input = {a: 10};
  const expectedOutput = {a: 20};

  const output = myFunction(input);

  expect(output).toEqual(expectedOutput);
  expect(input).toEqual(input); // will always pass
});

even if input get mutated, the second assertion will always pass because we are comparing input to itself. Instead, provide an expectedInput variable that has same value as input.

test('Ensure purity', function() {
  const input = {a: 10};
  const expectedInput = {a: 10};

  const expectedOutput = {a: 20};

  const output = myFunction(input);

  expect(output).toEqual(expectedOutput);
  expect(input).toEqual(expectedInput); // will check that input was not mutated
});

purify's People

Contributors

dmitrigrabov avatar

Watchers

 avatar  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.