FaasJS
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文

Documents / @faasjs/browser / setMock

Function: setMock()

setMock(handler): void

Set mock handler for testing

Parameters

handler

MockHandler

mock handler, set null or undefined to clear mock

Returns

void

Example

import { setMock } from '@faasjs/browser'

setMock(async (action, params, options) => {
  return {
    status: 200,
    data: {
      name: 'FaasJS'
    }
  }
})

const client = new FaasBrowserClient('/')

const response = await client.action('path') // response.data.name === 'FaasJS'