10mock 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

10mock

mockserver 是一个轻量级库,可帮助您模拟 API 请求快速和容易。

Installation

10mock 可以全局安装:

npm install -g 10mock

10mock -p 8080
[10mock]: Server is running at http://localhost:8080

或作为常规 NPM 模块:

npm install -D 10mock
npx 10mock

[10mock]: Server is running at http://localhost:8000

可用选项:

  1. -p \run the mock server on the specified port, default port is 8000.
  2. -x \run the mock server as proxy server

10mock 还提供易于使用的客户端:

import Api from '10mock';
export const api = new Api(optional-port);

10mock server client usage:

  1. api.finishTest() - remove all mocked routes.
  2. api.nock(path).method(method).status(status).send(mocked-response);
  • Create new mocked route → returns object with these entities:
  • getCount → function thats returns the number of requests sent to this route.
  • getStubRequests → function thats returns all the requests sent to this route.
  • getStats → function thats returns getStubRequests and getCount results.
  • deleteRoute → function thats remove this mocked route.

10mock

mockserver is a lightweight library that will help you mock your APIs requests fast and easy.

Installation

10mock can be installed globally :

npm install -g 10mock

10mock -p 8080
[10mock]: Server is running at http://localhost:8080

or as a regular NPM module:

npm install -D 10mock
npx 10mock

[10mock]: Server is running at http://localhost:8000

Available options:

  1. -p \run the mock server on the specified port, default port is 8000.
  2. -x \run the mock server as proxy server

10mock also supplies easy to use client:

import Api from '10mock';
export const api = new Api(optional-port);

10mock server client usage:

  1. api.finishTest() - remove all mocked routes.
  2. api.nock(path).method(method).status(status).send(mocked-response);
  • Create new mocked route → returns object with these entities:
  • getCount → function thats returns the number of requests sent to this route.
  • getStubRequests → function thats returns all the requests sent to this route.
  • getStats → function thats returns getStubRequests and getCount results.
  • deleteRoute → function thats remove this mocked route.
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文