GitHub
02/08/2023, 10:37 AM"@pact-foundation/pact": "10.4.1",
• Node Version: v16.13.1
Issue Checklist
Please confirm the following:
☑︎ I have upgraded to the latest
☑︎ I have the read the FAQs in the Readme
☑︎ I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures
☐ I have set my log level to debug and attached a log file showing the complete request/response cycle
☐ For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem
Expected behaviour
Header should be parsed as a string, without default behaviour of splitting it by comma for every possible HTTP header.
Actual behaviour
No matter what value is passed in a HTTP Header and what is its name it is always split if it has a comma in it.
Steps to reproduce
Given the following code:
provider
.given('assignments exist')
.uponReceiving('a request for all assignments')
.withRequest({
method: 'GET',
path: '/api/assignments',
headers: {
Accept: 'application/json',
'X-Custom-Header': '{"id":"asd-asdasd-sd","additionalInfo":"some additional string"}'
}
})
.willRespondWith({
status: 200,
headers: { 'Content-Type': 'application/json' },
body:[]
});
return provider.executeTest(async mockserver => {
const response = await axios.get(`${mockserver.url}/api/assignments`, {
headers: {
'X-Custom-Header': '{"id":"asd-asdasd-sd","additionalInfo":"some additional string"}'
}
});
expect(response.data).toEqual([]);
});
This test fails as pact splits the header by comma and tries to compare a part of invalid JSON between what was sent and what was received.
When the header is a string that does not contain any commas it works.
Relevant log files
pact@10.4.1: Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was incorrect:
GET /api/assignments
1.0 Mismatch with header 'X-Custom-Header': Expected '' to be equal to '{"id":"asd-asdasd-sd"' for value at index 0
pact-foundation/pact-js