Provide a way to force the approval of a snapshot before it can be used as matching criteria.
In "snapshot mode", a snapshot that is created for first time is supposed to represent the behaviour of the subject under test.
In "approval mode", a snapshot that is created for first time has to wait to be approved by a human actor before being used as matching criteria.
Known approaches
Approvals test uses the file name to mark a snapshot file as approved of pending. You need to rename the file in order to mark as approved.
Other libraries uses an env variable to run the test. If the env variable has certain value, the snapshot is considered approved.
Proposal
Do this in the test
First, you execute the test in "approval mode", so test will never pass.
golden.ToApprove(t, subject)
Once you are happy with the output, back to verify
golden.Verify(t, subject)
Pros
Explicit in the test code. You always know if your snapshot is valid or not
Convenient: you don't need to move away from code, manage files o worried about env vars, even if they are temporal
Cons
You need to be sure that all snapshots are approved before committing changes, given that tests with ToApprove status are going to fail in CI. (This could be Pro, if you ask me, and it is no different from other systems)
API
golden.ToApprove(t, subject)
This will kind of a decorator around Verify. It will set a flag so the system can decide if it needs to compare snapshot and subject. Snapshot creation has to be forced even if previous snapshot exists.
A reminder to approve the snapshot can be added to the report.
Provide a way to force the approval of a snapshot before it can be used as matching criteria.
In "snapshot mode", a snapshot that is created for first time is supposed to represent the behaviour of the subject under test. In "approval mode", a snapshot that is created for first time has to wait to be approved by a human actor before being used as matching criteria.
Known approaches
Proposal
Do this in the test
First, you execute the test in "approval mode", so test will never pass.
Once you are happy with the output, back to verify
Pros
Cons
API
This will kind of a decorator around Verify. It will set a flag so the system can decide if it needs to compare snapshot and subject. Snapshot creation has to be forced even if previous snapshot exists.
A reminder to approve the snapshot can be added to the report.