fix(app): roll the preview back on a throwing accept or a non-trap failure
This commit is contained in:
1 parent
173be5949a
commit
bc43a1b86b
3 files changed
+85
-34
No files matched your search
@@ -202,4 +202,39 @@ describe('replaceDocument accept hook', () => {
|
||||
expect(stateOf(preview)).toEqual(before)
|
||||
preview.free()
|
||||
})
|
||||
|
||||
it('rolls back when accept throws, and rethrows', () => {
|
||||
const preview = draft()
|
||||
const before = stateOf(preview)
|
||||
expect(() =>
|
||||
preview.replaceDocument(renamed(preview.document, 'Boom'), () => {
|
||||
throw new Error('boom')
|
||||
}),
|
||||
).toThrow('boom')
|
||||
expect(stateOf(preview)).toEqual(before)
|
||||
forceRebuild()
|
||||
expect(stateOf(preview)).toEqual(before)
|
||||
preview.free()
|
||||
})
|
||||
|
||||
it('rolls back on a non-trap internal failure of state', () => {
|
||||
const preview = draft()
|
||||
const before = stateOf(preview)
|
||||
const handle = (
|
||||
preview as unknown as { handle: { call(op: string, i: string): string } }
|
||||
).handle
|
||||
const real = handle.call.bind(handle)
|
||||
let failed = false
|
||||
handle.call = (op, input) => {
|
||||
if (op === 'preview.state' && !failed) {
|
||||
failed = true
|
||||
return '{"ok":false,"kind":"internal"}'
|
||||
}
|
||||
return real(op, input)
|
||||
}
|
||||
const outcome = preview.replaceDocument(renamed(preview.document, 'Perdu'))
|
||||
expect(outcome).toMatchObject({ ok: false, failure: { kind: 'internal' } })
|
||||
expect(stateOf(preview)).toEqual(before)
|
||||
preview.free()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user