Mini Application
Express app and sinon mocks to the rescue!
Installation
npm i mini-application --save
yarn add -S mini-application
const MiniApplication = const miniApp = ;
Stub
What happens when you wrap Express middleware with Sinon stub? See below:
Stub simple endpoint
const MiniApplication = const miniApp = ; miniApp; miniApp;
Stub different responses
miniApp ;
Stub specific method only
miniApp;
Use sinon helper
// respond with jsonminiApp;// or set the status codeminiApp;// or just send a textminiApp;
Events
It's often helpful to get nice callback the verify the expectations
Simple event emitted for path
request;miniApp;
Interactive
Sometimes it's hard to write a good test without manual verification first. Miniapp should help here too:
bin/mini-applicationminiApp - listening on 3000miniApp > stubApp.respond# now open http://localhost:3000/ in the browser to see the response # then you can inspect all requests which were made to the miniApp instance: miniApp >
Extendable
For easier testing custom logic can be wrapped as a class extending the MiniApplication base:
{ superoptions; this; } miniApp = ;miniApp ;