codeceptjs-httpmock
CodeceptJS helper for HTTP Mock with Mochawesome logging
Last updated a year ago by kronoslive .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install codeceptjs-httpmock 
SYNC missed versions from official npm registry.

codeceptjs-httpmock

codeceptjs-httpmock is CodeceptJS helper which wraps mockttp library to manage http mock in tests.

NPM package: https://www.npmjs.com/package/codeceptjs-httpmock

Configuration

This helper should be configured in codecept.json/codecept.conf.js

  • port: mock port. Default 9037
  • debug: - (optional) enable debug logs. Default false

Example:

{
   "helpers": {
     "HTTPMock" : {
       "require": "codeceptjs-httpmock",
       "debug": false,
       "port": 9037
     }
   }
}

respondWith

Set up mock for method и urlPath. Response calculates in callback function.

  I.respondWith('POST', '/url', (req) => {
    if (req.body.status === 'good') {
      return { status: 200, body: '{"Status":"OK"}', headers: { 'Content-Type': 'application/json' } };
    }
    return { status: 400, body: { error: 'badman' } }
  });

Parameters

  • method - request method
  • urlPath - relative path for mock
  • callback - (optional) callback function. Should return response object
  • ctx - (optional) mockttp context

expectRequestUntil

Validates that request comes for method and urlpath that satisfies predicate function

I.expectRequestUntil('POST', '/myPath', req =>
    req.body.json.param === 'myValue'
  );

Parameters

  • method - request method
  • urlPath - relative path for mock
  • predicate - (optional) specify predicate function. Predicate function should return true value.
  • timeout - (optional) timeout in ms. After the end of the timeout method will throw Error

dontExpectRequestUntil

Validates that no request comes for method and urlpath that satisfies predicate function

I.dontExpectRequestUntil('POST', '/myPath', req =>
    req.body.json.param === 'myValue'
  );

Parameters

  • method - request method
  • urlPath - relative path for mock
  • predicate - (optional) specify predicate function. Predicate function should return false value.
  • timeout - (optional) timeout in ms. After this timeout helper will check that there were no requests

grabServerRequests

Get requests that comes to mock server by method and urlPath

let requests = await I.grabServerRequests('POST', '/myPath');

Parameters

  • method - request method
  • urlPath - relative path for mock

Current Tags

  • 0.0.7                                ...           latest (a year ago)

7 Versions

  • 0.0.7                                ...           a year ago
  • 0.0.6                                ...           a year ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |