Giter Club home page Giter Club logo

nock-with-jest's Introduction

A simple demo to showoff Nock usage with Jest

Explainer

  1. index.js is a module which sends requests to the server and this module has to be tested.
  2. server.js is used to create a server which responds with a delay of 1600 ms.
  3. test/withoutnock.test.js contains test which when run, lets the module send actual requests to server.
  4. test/withnock.test.js contains test which when run, intercepts the request made by the module.

How To Run

  1. Open server using npm run server.
  2. Run tests in watch mode using npm run test:watch.

What to make of it

  1. When you run the tests you'll notice that withoutnock.test.js takes around 1600 ms to complete
  2. However, withnock.test.js takes around 5 ms only.
  3. Also if you monitor the server logs, they will show that only one request was received by the server when the tests were run.
  4. All this happens because in withnock.test.js nock intercepts the requests and don't actually send the request to server, hence don't wait 1600 ms for the server to respond.

nock-with-jest's People

Contributors

itaditya avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.