All Projects → lawvs → mocat

lawvs / mocat

Licence: MIT license
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.

Programming Languages

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

Projects that are alternatives of or similar to mocat

Mockito
Most popular Mocking framework for unit tests written in Java
Stars: ✭ 12,453 (+46022.22%)
Mutual labels:  mock, testing-tools, mocking-framework
main
Mocks Server monorepo
Stars: ✭ 109 (+303.7%)
Mutual labels:  mock, mock-server, testing-tools
ruby-dns-mock
DNS mock server written on 💎 Ruby. Mimic any DNS records for your test environment with fake DNS server.
Stars: ✭ 50 (+85.19%)
Mutual labels:  mock, mock-server, testing-tools
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+1881.48%)
Mutual labels:  mock, mock-server, mocking-framework
servirtium-java
Service Virtualized HTTP - to help service test automation stay fast and consistent
Stars: ✭ 16 (-40.74%)
Mutual labels:  mock-server, testing-tools, mocking-framework
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (+755.56%)
Mutual labels:  mock, testing-tools, mocking-framework
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (+562.96%)
Mutual labels:  mock, testing-tools
Killgrave
Simple way to generate mock servers written in Go
Stars: ✭ 180 (+566.67%)
Mutual labels:  mock, mock-server
json-fake-server
Simple way to create http server (node js) https://www.npmjs.com/package/test-fake-server
Stars: ✭ 15 (-44.44%)
Mutual labels:  mock, mock-server
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 (+700%)
Mutual labels:  mock, mocking-framework
Weld
Full fake REST API generator written with Rust
Stars: ✭ 146 (+440.74%)
Mutual labels:  mock, mock-server
Openapi Mock
OpenAPI mock server with random data generation
Stars: ✭ 202 (+648.15%)
Mutual labels:  mock, mock-server
Jest Mock Extended
Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
Stars: ✭ 224 (+729.63%)
Mutual labels:  mock, mocking-framework
Mockinizer
An okhttp / retrofit api call mocking library
Stars: ✭ 176 (+551.85%)
Mutual labels:  mock, mock-server
Charlatan
Go Interface Mocking Tool
Stars: ✭ 195 (+622.22%)
Mutual labels:  mock, testing-tools
Httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module
Stars: ✭ 1,930 (+7048.15%)
Mutual labels:  mock, testing-tools
Pegomock
Pegomock is a powerful, yet simple mocking framework for the Go programming language
Stars: ✭ 215 (+696.3%)
Mutual labels:  mock, mocking-framework
Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+12670.37%)
Mutual labels:  mock, mock-server
go-smtp-mock
SMTP mock server written on Golang. Mimic any 📤 SMTP server behavior for your test environment with fake SMTP server.
Stars: ✭ 76 (+181.48%)
Mutual labels:  mock-server, testing-tools
Ava Playback
📼 🚀 Record and playback http requests from your ava tests
Stars: ✭ 124 (+359.26%)
Mutual labels:  mock, testing-tools

Mocat

CI npm

Mocat is a development toolbar for mocking. It allows you to interactively develop and test network requests. This library is inspired by cypress.

demo

Installation

To install and save in your package.json dev dependencies, run:

# With npm
npm install --save-dev mocat

# Or with yarn
yarn add --dev mocat

# Or with pnpm
pnpm add --save-dev mocat

Usage

// mock.ts
import { create } from 'mocat'

const app = create()

app.mockRoute({
  name: 'login api',
  // Specify the URL to match
  url: '/api/login',
  // Create scenarios
  scenarios: [
    {
      name: 'login success',
      response: {
        username: 'Alice',
        msg: 'ok',
      },
    },
    {
      name: 'login fail',
      desc: 'username or password incorrect',
      // The HTTP status code to send.
      status: 400,
      // HTTP headers to accompany the response.
      headers: { 'Content-Type': 'application/json' },
      // Serve a static string/JSON object as the response body.
      response: {
        msg: 'username or password incorrect',
      },
    },
  ],
})

Then load it from the application entry:

// main.ts
import { App } from './App'

// Load React
ReactDOM.render(<App />, document.getElementById('app'))
// Or Vue
createApp(App).mount('#app')

if (process.env.NODE_ENV !== 'production') {
  await import('./mock')
}

API

MockRoute

export interface MockRoute {
  /**
   * The name of API.
   */
  name?: string
  desc?: string
  /**
   * Match against the full request URL.
   * If a string is passed, it will be used as a substring match,
   * not an equality match.
   */
  url: string | RegExp | ((url: string) => boolean)
  /**
   * Match against the request's HTTP method.
   * All methods are matched by default.
   */
  method?:
    | 'GET'
    | 'POST'
    | 'OPTIONS'
    | 'PUT'
    | 'DELETE'
    | 'HEAD'
    | 'TRACE'
    | 'CONNECT'
  scenarios?: NetworkScenario[]
}

NetworkScenario

export interface NetworkScenario {
  /**
   * The name of scenario.
   */
  name: string
  /**
   * The description of scenario.
   */
  desc?: string
  /**
   * The HTTP status code to send.
   * @default 200
   */
  status?: number
  /**
   * HTTP headers to accompany the response.
   * @default {}
   */
  headers?: Record<string, string>
  /**
   * Serve a static string/JSON object as the response body.
   */
  response?: ConstructorParameters<typeof Response>[0] | Record<string, any>
  error?: any
}

Other similar projects

License

MIT

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