I'm currently starting to create some pact tests a...
# pact-js
t
I'm currently starting to create some pact tests and with larger objects I see a lot of test data duplication between the body pact should return and the object I'm using as the actual value for the later assertion, especially for larger models. In https://github.com/pact-foundation/pact-js/blob/1cbe0576bba9544e02b92f82dffccf1603254c30/examples/v3/typescript/test/user.spec.ts#L24 the same object reference is used at both locations. In practice the mocked body will still have some matchers wrapping the values, so I thought about writing an "unwrapping" function, that converts the matching object to the assertion object, but I am unsure if I that will make the tests less reliable. On the other hand, it would also enable the usage of test data builders with sane default values, which would be valuable for models used in multiple endpoints. Has anyone any experience with or ideas on this?
šŸ‘‹ 1
m
t
Awesome, thanks!
But this will not created dates for
date
and
datetime
matchers, right?
But I can probably create my own version of reify that supports this and any other custom conversions.
m
I’m not sure I follow, the
reify
function simply strips off the matchers - whatever example values that were associated should remain
t
Yes, but what is transferred as a date string will actually be parsed to a JavaScript Date object, by my client logic, which may not be matched as identical. Example: A ISO8601 Date (without time) is transferred via HTTP. For assertion, the test framework will stringify it, but as a JavaScript Date object will always include a time as well, the resulting string will also include a time again. This will result in a mismatch and cause the test to fail.
šŸ‘ 1
m
ah, I see