🚀 Feature: when tests fail, say "I expect these new values" and replace my expected values with the actual ones (snapshots) #5182
Labels
status: in triage
a maintainer should (re-)triage (review) this issue
type: feature
enhancement proposal
Feature Request Checklist
faq
label, but none matched my issue.Overview
Hello, I'm using Mocha for plenty of tests involving lots of data from Prometheus. I'm querying the data, formatting it, and providing API responses.
Sometimes I'll make an adjustment to the code and the tests will fail for good reason - but then I have to copy the new results out of the diff and say yep, these values are fine, accept them. A good reason might be: I now want 10 arrays of data instead of 5 so I can provide more accuracy, but my tests expect five (with exact values in them).
I'd like a flag like
--accept-incoming
(or similar, so long as it exists) so that when I get a failure like (my big array is not deeply equal to my big other array) - I can just say: yep, I know, and I want my expected response to now be that.Instead I'm here deleting the expected response object's data, copying that out of the diff, JSON formatting it in VScode, and pasting it in. Fine, but I've got hundreds of tests that rightfully fail as I'm getting different (but better) values out.
Can Mocha do this for me already? Have I missed a trick? Cheers
Suggested Solution
Add an
--accept-incoming
flag so that when Mocha test(s) fail, instead of me manually fixing all of my assertions, the values will "simply" be replaced with what it now sees.In your package.json scripts you might have:
npm t
-> run your mocha tests, greatnpm t:fix
could be -> go ahead and accept all of those failures by making my assertions match what is now foundAlternatives
Doing it manually - it's a pain with vast amounts of data
The text was updated successfully, but these errors were encountered: