Describe any API or Service you need mocked. Supports API Blueprint and Swagger API Description formats.
Use cases
3rd party APIs
- Your app is calling GitHub API, weather API, Trello API, …
- Describe endpoints in API Description format like API Blueprint (or ask API provider for API Description)
- Add it as a test fixture and let apish create mock for you:
; // Run your tests with mocked requests against GitHub API
(Micro)services
- Have all your services publish API Description onto (private) npm. Use semver to version it and tools like Dredd to test its implementation
- When you depend on another service, just require its package with API Description and run tests against its mocks, that are always in sync with implementation
- You can always compare version you've tested against to what is currently running in your environment
; ; // Run your tests…
Installation
$ npm i apish -D
Usage
; // In your test runnerlet mockResult = {};; // Cleanup;
Arguments
const mockedApi = ;
apiDescription
(string) - API Blueprint or Swagger API Descriptionoptions
(OPTIONAL, object)host
(string) - overwrite specified host (base URL) that should be used
returns Promise
Resolved promise returns object with methods:
restore()
- clears all mocks for this host
License
MIT