rest()
and resetBehavior()
stops onAnyCommand()
working (DynamoDB)
#67
Labels
bug
Something isn't working
Checklist
Bug description
When using the
reset()
function between tests and usingonAnyCommand()
to set a default response there is no error however the default response does not seem to work.As part of debugging the issue it was noticed in the comments that
reset()
basically performsresetHistory()
andresetBehavior()
. We tried setting these individually and (as expected) were able to pin it down to just theresetBehavior()
function.Rightly or wrongly to avoid asserting the arguments of the function call I was using the
onAnyCommand().rejects()
to reject any calls by default and then using more specificon()
to catch the calls I was expecting.This all works but when it came to mutation testing and deliberately trying to force tests to fail if the code isn't as expected the tests were passing when in specific orders.
The first test would use the
onAnyCommand()
response as expected, between tests (usingbeforeEach()
) we usereset()
to remove any behaviours and history and then doonAnyCommand().rejects()
again, however in subsequent tests we do not see this being used and instead the mock resolves the promise.In the below we expect both tests to pass which they do, however if we change the service name on L30 to something else,
NOT-my-service
for example, the test passes when it should fail. Run the same test in isolation and it fails as expected.(for clarity this is a slightly simplified version to help convey the issue, we are making mutations in the
.ts
not the.test.ts
which is why this may seem an odd way of doing things!)Final few observations, if we switch the order of the tests then the mutation fails as expected.
Also strangely if we use the below as our describe block, both tests pass as expected, if we change the assertion to
removeLock('NOT-my-service')
, the test fails, as expected. Yet changing the mock toKey: {lock: {S: 'NOT-my-service'}},
leaving the assertion as the originalremoveLock('my-service')
the test passes when the same fail is expected.Environment
The text was updated successfully, but these errors were encountered: