MockServer has the following internal state:

  • recorded requests
  • active expectations
  • recorded expectations
  • logs

State can be cleared from MockServer selectively:

  • use type to select with type of state to clear
  • use a request matcher to clear matching items
new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST")
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  })
  .then(
    function () {
      console.log("cleared state that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.LOG
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  }, 'LOG')
  .then(
    function () {
      console.log("cleared recorded requests and logs that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear?type=LOGS" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

new MockServerClient("localhost", 1080).clear(
    request()
        .withPath("/some/path")
        .withMethod("POST"),
    ClearType.EXPECTATIONS
);
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .clear({
    'path': '/some/path'
  }, 'EXPECTATIONS')
  .then(
    function () {
      console.log("cleared expectations that matches request matcher");
    },
    function (error) {
      console.log(error);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/clear?type=EXPECTATIONS" -d '{
    "path": "/some/path"
}'

See REST API for full JSON specification

MockServer can be reset completely, as follows:

new MockServerClient("localhost", 1080).reset();
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
  .reset()
  .then(
    function () {
      console.log("reset all state");
    },
    function (error) {
      console.log(error);
    }
  );

See REST API for full JSON specification

curl -v -X PUT "http://localhost:1080/mockserver/reset

See REST API for full JSON specification