Giter Site home page Giter Site logo

jest-mocker's Introduction

jest-mocker

A mocking helper for those who would like to explicitly mock modules preserving compile-time type and refactoring safety.

Usage

Inject a Mocker instance as a global (e.g. mocker) to use during your tests.

Then you can use e.g. mocker.mockAllFunctionsInObject(ClassOrObject) to replace all functions within that object with mocks.

The function returns a strongly typed object containing mocks, so you can setup and verify calls on them.

On the other hand, you can continue invoking any method as usual through ClassOrObject, and your mocks will be called instead.

API

  1. mockAllFunctionsInObject - mocks all functions in an object and resets their default implementation to always returning undefined.
  2. spyOnAllFunctionsInObject - mocks all functions in an object and keeps their real implementation by default.
  3. mockOneFunctionInObject - mocks just one function in an object and resets its default implementation to always returning undefined. The rest of the functions are not mocked.
  4. mockAllButOneFunctionInObject - mocks all functions but one in an object and resets their default implementation to always returning undefined. The remaining function is not mocked.
  5. spyOnAllButOneFunctionInObject - mocks all functions except one in an object and keeps their real implementation by default. The remaining function is not mocked.

All methods return a strongly typed object with relevant functions marked as mock instances.

jest-mocker's People

Contributors

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