Class ExpectationToJavaScriptSerializer

java.lang.Object
org.mockserver.serialization.code.ExpectationToJavaScriptSerializer

public class ExpectationToJavaScriptSerializer extends Object
Generates copy-paste-ready JavaScript/TypeScript expectation code for the MockServer Node.js client (mockserver-client).

Unlike the Java client (which requires the typed builder DSL, hence the ExpectationToJavaSerializer family), the Node client accepts an expectation as a plain JSON object via mockAnyResponse(...). So the "code" for JavaScript is simply each expectation's existing JSON serialization embedded in a client call, preceded by the require preamble.

Example output for a single expectation:

 const { mockServerClient } = require('mockserver-client');

 mockServerClient("localhost", 1080).mockAnyResponse({
   "httpRequest" : { ... },
   "httpResponse" : { ... }
 });
 
One mockAnyResponse(...) call is emitted per expectation.
Author:
jamesdbloom
  • Constructor Details

    • ExpectationToJavaScriptSerializer

      public ExpectationToJavaScriptSerializer(ExpectationSerializer expectationSerializer)
  • Method Details