This code provides examples how to setup contract testing using Angular as a Consumer and Spring Boot as a Provider. Read more about it in my blog post here.
This repository contains 2 Consumers, both are Angular front-ends. Contracts are written to pacts root folder.
The difference is the used framework to setup the Pact tests: Karma and Jest.
Currently on Angular 8.
Run with npm run test/yarn test/ng test.
src/app/user.service.ts: Angular service that calls REST backend to manage usersuser.service.pact.spec.ts: Karma/Jasmine consumer Pact test for user servicekarma.conf.js: Karma configuration for consumer Pact tests
Updated to Angular 10.
Run with npm run test/yarn test/ng test.
src/app/user.service.ts: Angular service that calls REST backend to manage usersuser.service.pact.spec.ts: Karma/Jasmine consumer Pact test for user servicejest.pact.config: Jest configuration for consumer Pact testspact/jest/setupJest.ts: Jest setup file to setup Pact
Don't forget "emitDecoratorMetadata": true in the tsconfig.json file to prevent Can't resolve all parameters for Component.
See thymikee/jest-preset-angular#288
Provider is a Spring Boot backend server which provides the user endpoint.
Run with mvn clean verify.
UserController.java: Spring Boot user endpointUser.java: Model representing a userUserServiceVerificationTest.java: Pact Provider test, verifies contracts found inpactsroot folder.