Skip to content

Commit f437ec3

Browse files
authored
chore(readme): Add common gotchas section
1 parent 46eca53 commit f437ec3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, provider => {
7474
//
7575
// jest-pact takes care of validating and tearing
7676
// down the provider for you.
77-
beforeEach(() =>
77+
beforeEach(() => // note the implicit return.
78+
// addInteraction returns a promise.
79+
// If you don't want to implict return,
80+
// you will need to `await` the result
7881
provider.addInteraction({
7982
state: "Server is healthy",
8083
uponReceiving: 'A request for API health',
@@ -101,7 +104,7 @@ pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, provider => {
101104
// This is often the same as the object that was
102105
// in the network response, but (as illustrated
103106
// here) not always.
104-
it('returns server health', () =>
107+
it('returns server health', () => // implicit return again
105108
client.health().then(health => {
106109
expect(health).toEqual('up');
107110
}));
@@ -161,6 +164,18 @@ pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, provider => {
161164
}));
162165
});
163166
```
167+
## Common gotchas
168+
169+
* Forgetting to wait for the promise from `addInteraction` in `beforeEach`.
170+
You can return the promise, or use `async`/`await`. If you forget this,
171+
your interaction may not be set up before the test runs.
172+
* Forgetting to wait for the promise of your API call in `it`. You can
173+
return the promise, or use `async`/`await`. If you forget this, your
174+
test may pass before the `expect` assertion runs, causing a potentially
175+
false success.
176+
* Not running jest with `--runInBand`. If you have multiple test files that
177+
write to the same contract, you will need this to avoid intermittent failures
178+
when writing the contract file.
164179
165180
# API Documentation
166181

0 commit comments

Comments
 (0)