Question around approval testing, is there a way t...
# http4k
m
Question around approval testing, is there a way to setup "Scrubbers", for instance to get rid of identifiers/timestamps in the text?
m
My solution is just
Copy code
approver.assertApproved(
                output
                    .replace(noteId1.value.toString(), "{{NOTE_ID1}}")
                    .replace(noteId2.value.toString(), "{{NOTE_ID2}}")
            )
No idea if there's a better way though
d
As a rule, every test should be entirely deterministic so there should be no need for this at all. ie. absolutely zero randomness inside the test environment. You should extract the sources of randomness and inject them into your application environment - this includes clocks, random id generators and the system environment.
❤️ 2
m
For some reason I never put 2 and 2 together on doing that for the ID generator (despite doing it for everything else), good point!
m
@dave sure that's a solution, at this point I didn't have anything that would care about identifiers (despite them need to be different) so I didn't need that, I can abstract it away now though. Thanks.