Code Monkey home page Code Monkey logo

jest-practice's Introduction

jest-practice

In this exercise, you will write a few practical tests for JavaScript functions using the Jest library. You should make sure you follow the AAA pattern to make your tests easier for other developers to read and understand. You will also try to use the TDD approach in practice.

Instructions

Task 1

  • Write a function stringLength(string) that takes any string as an argument and returns its characters count.
  • Now write a test for this function.
  • Next, expand your function to make it check if the string is at least 1 character long and not longer than 10 characters. Throw errors if those conditions are not met.
  • Add tests for the new functionality.

Task 2

  • Write a function reverseString(string) function. It should take a string as an argument and return it reversed.
  • Write at least one test for this function.

Task 3

In this task, you will need to write several tests for each tested function. You could write all of your tests directly at the top level, but it's better to group related tests so their output is more readable. Jest has the describe() method just for that. Read about it here and apply it in your tests for this task:

  • Write a simple calculator class or object, which will have 4 methods: add, subtract, divide, and multiply.
  • Write at least 3 tests for each of the calculator methods.
  • Group tests for each method using describe() method.

Task 4

In this task we're going to do things differently:

  • Start by writing a test for a capitalize(string) function. Your test should make sure that this function takes a string as an argument and returns that string with the first character capitalized.
  • Run your test - it should fail because you don’t have the capitalize(string) function implemented yet.
  • Now make your tests green by implementing the capitalize(string) function. Think about what the minimum amount of code is necessary to pass this test and write it.

jest-practice's People

Contributors

omarsalem7 avatar

Stargazers

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