Use Snapshots to revert test changes
masterSnapshots allow you to capture the state of spies, stubs, parameters, and formatters, and then revert to that state. This is useful in after_each blocks to ensure test isolation.
- Create a snapshot with
assert:snapshot(). - Call
snapshot:revert()to undo changes made to spies, stubs, parameters, or formatters.
describe("Showing use of snapshots", function()
local snapshot
before_each(function()
snapshot = assert:snapshot()
end)
after_each(function()
snapshot:revert()
end)
it("does some test", function()
-- spies or stubs registered here, parameters changed, or formatters added
-- will be undone in the after_each() handler.
end)
end)