← Back to JavaScript | Main README
Pact-JS is a library that allows you to implement Consumer Driven Contracts using the Pact framework in JavaScript. It is particularly useful for testing interactions between front-end and back-end services.
You can find the source code and more details about Pact-JS at the following link:
For detailed usage and documentation, refer to the Pact-JS Documentation.
To install Pact-JS, use npm:
npm install @pact-foundation/pactHere is a basic example of how to use Pact-JS:
const { Pact } = require('@pact-foundation/pact');
const path = require('path');
const provider = new Pact({
consumer: 'ConsumerName',
provider: 'ProviderName',
port: 1234,
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'INFO',
});
provider.setup()
.then(() => {
// Your test code here
})
.finally(() => provider.finalize());