All Projects → Typescript-TDD → jest-ts-auto-mock

Typescript-TDD / jest-ts-auto-mock

Licence: other
Jest test utility with automatic mock creation for interfaces and classes

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jest-ts-auto-mock

Mimesis
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.
Stars: ✭ 3,439 (+2192.67%)
Mutual labels:  mock, fake
Sns
Fake Amazon SNS
Stars: ✭ 94 (-37.33%)
Mutual labels:  mock, fake
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-67.33%)
Mutual labels:  mock, fake
Stubmatic
Mock HTTP calls without coding. Designed specially for testing and testers.
Stars: ✭ 118 (-21.33%)
Mutual labels:  mock, fake
Fake Xrm Easy
The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you
Stars: ✭ 216 (+44%)
Mutual labels:  mock, fake
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-90.67%)
Mutual labels:  mock, fake
Fakerator
Random fake data generator with localization for Javascript in Node.js and browser
Stars: ✭ 91 (-39.33%)
Mutual labels:  mock, fake
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+42%)
Mutual labels:  mock, fake
Ts Auto Mock
Typescript transformer to unlock automatic mock creation for interfaces and classes
Stars: ✭ 204 (+36%)
Mutual labels:  mock, fake
Wabbit
Golang AMQP mocking library
Stars: ✭ 137 (-8.67%)
Mutual labels:  mock, fake
xrm-mock
📚 A fake implementation of the Xrm object model. Written in TypeScript against @types/xrm definitions.
Stars: ✭ 64 (-57.33%)
Mutual labels:  mock, fake
ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (-31.33%)
Mutual labels:  mock, fake
better-mock
Forked from Mockjs, Generate random data & Intercept ajax request. Support miniprogram.
Stars: ✭ 140 (-6.67%)
Mutual labels:  mock, fake
falso
All the Fake Data for All Your Real Needs 🙂
Stars: ✭ 877 (+484.67%)
Mutual labels:  mock, fake
fakey-json
This is a utility for mocking json data that pretends the api response data with JSON format.
Stars: ✭ 27 (-82%)
Mutual labels:  mock, fake
Openapi Sampler
🔠 Tool for generation samples based on OpenAPI(fka Swagger) payload/response schema
Stars: ✭ 83 (-44.67%)
Mutual labels:  mock, fake
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (-33.33%)
Mutual labels:  mock, fake
Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (+68.67%)
Mutual labels:  mock, fake
moq.ts
Moq for Typescript
Stars: ✭ 107 (-28.67%)
Mutual labels:  mock, fake
Paw-FakerDynamicValue
A dynamic value extension for Paw using Faker to generate data
Stars: ✭ 16 (-89.33%)
Mutual labels:  mock

Jest Ts Auto Mock

Actions Status

This is a library that extend ts-auto-mock to be used with jest

The intention of the library is to automatically assign jest mock to functions giving you type safety

Requirements

typescript@^3.2.2
ts-jest@>=24 <27

Installation

  • A Transformer needs to be provided at compile time. We need to tell ts-jest to use ttypescript that allow us to use a transformer.

IMPORTANT:

  • set "cacheBetweenTests" as false

  • Add the transformer to your ts config

    {
      "compilerOptions": {
        ...
        "plugins": [
          { "transform": "ts-auto-mock/transformer", "cacheBetweenTests": false }
        ]
      }
    }
    • Enable ttypescript into the ts-jest configuration
       ...
       "globals": {
          "ts-jest": {
            "compiler": "ttypescript"
          }
        }
  • provide jest-ts-auto-mock config before your test

"jest": {
    ...
    "setupFiles": [
      "<rootDir>/config.ts"
    ]
   ...
  },
  • config file
import 'jest-ts-auto-mock'

Examples

ts-jest-ttypesctipt

Usage

  1. create an interface
interface Interface {
    methodToMock: () => string
}
  1. create a mock
const mock: Interface = createMock<Interface>();
  1. get the method mock

You can get the method spy in 2 different ways

Through method

import { On, method } from "ts-auto-mock/extension";
const mockMethod: Jest.Mock = On(mock).get(method(mock => mock.methodToMock));

Through string

import { On, method } from "ts-auto-mock/extension";
const mockMethod: Jest.Mock = On(mock).get(method('methodToMock'));
  1. trigger the method
someMethodThatWillTriggerInterfaceA();
expect(mockMethod).toHaveBeenCalled();

Authors

License

This project is licensed under the MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].