Read Spring Cloud Contract JSON directly in your consumer contract tests and banish magic numbers once and for all! 😱
npm install spring-cloud-contract-json-reader
yarn install spring-cloud-contract-json-reader
- Set environment variable
CONTRACT_JSON_BASE_PATHto wherever your contract test json is located relative to the root of your project's git repository. E.g.:
Note: No need for leading or trailing slashes.
- Import the Spring Cloud Contract JSON Reader into your tests and start asserting on response body data!
const readJsonContractFile = require('spring-cloud-contract-json-reader');const contractResponseBody = await readJsonContractFile('shouldReturnListOfSuperheroes.json');const response = await axios.fetch('');expect(response.data).toEqual(contractResponseBody);
Running Unit Tests ⚙
This library includes its own test suite. You'll need to install testing dependencies before you can run the tests:
After that's done, just run the tests with: