Skip to content

Commit

Permalink
doc: update Provider State callback info in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Nov 18, 2020
1 parent f0d55a8 commit a3dfdd1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ For example:
},
```
**NOTE:** Async callbacks and returning promises from the provider state callbacks is not currently supported.
### Using Pact with XML
You can write both consumer and provider verification tests with XML requests or responses. For an example, see [examples/v3/todo-consumer/test/consumer.spec.js](examples/v3/todo-consumer/test/consumer.spec.js).
Expand Down Expand Up @@ -1176,38 +1178,39 @@ requestFilter: req => {
Provider state callbacks have been updated to support parameters and return values. The first parameter is a boolean indicating whether it is a setup call
(run before the verification) or a tear down call (run afterwards). The second optional parameter is a key-value map of any parameters defined in the
pact file. Provider state callbacks can also return a map of key-value values. These are used with provider-state injected values, but support for that
will be added in a later release.
pact file. Provider state callbacks can also return a map of key-value values. These are used with provider-state injected values (see the section on that above).
```javascript
stateHandlers: {
"Has no animals": setup => {
if (setup) {
animalRepository.clear()
return Promise.resolve({ description: `Animals removed to the db` })
return { description: `Animals removed to the db` }
}
},
"Has some animals": setup => {
if (setup) {
importData()
return Promise.resolve({
return {
description: `Animals added to the db`,
count: animalRepository.count(),
})
}
}
},
"Has an animal with ID": (setup, parameters) => {
if (setup) {
importData()
animalRepository.first().id = parameters.id
return Promise.resolve({
return {
description: `Animal with ID ${parameters.id} added to the db`,
id: parameters.id,
})
}
}
},
```
**NOTE:** Async callbacks and returning promises from the provider state callbacks is not currently supported.
## Troubleshooting / FAQs
If you are having issues, a good place to start is setting `logLevel: 'DEBUG'`
Expand Down

0 comments on commit a3dfdd1

Please sign in to comment.