Learn / Errors and failures
Testing failures
A failure path is a path like any other: drive it, and assert what the reader sees.
Without a browser,
Trace.runfromfoldkit-remote/testingruns the realupdateand Subscriptions and holds every request; eachRespondtakes{ fail }to answer with an error.Trace.regressionsnames every step where a read that showed a value stopped showing it.tsimport { RemoteReadError } from 'foldkit-remote' import { Respond, Trace } from 'foldkit-remote/testing' const trace = await Trace.run(Data, { start: loaded, // a Model showing the project update, active: actives, client: server, // a fake RemoteClient, or the server's in-process one steps: [ Message.ClickedTryAgain(), Respond.read(Project, 'p1', { fail: new RemoteReadError({ message: 'The server is down' }) }), ], }) expect(Trace.regressions(trace, { project: Data.get(ProjectName, 'p1') })).toEqual([])A refusal made on the client is held to the server's by
Law.check(foldkit-remote/testing): it runs one declared write throughData.mutateand through the server, and compares what the client predicted, a refusal included, with what the server then holds. See Testing that a prediction is the truth.Diagnostics are asserted with
Diagnostics.collect(): provide itsreportto the Effect under test (hereprogram), then assert onreported,[]included.tsconst { report, reported } = Diagnostics.collect() await Effect.runPromise(Effect.provideService(program, Diagnostics.Reporter, report)) expect(reported).toEqual([])On a running page,
foldkit-plus/testing/playwright'sBehaviorswatches the page as drawn:tsimport { Behaviors } from 'foldkit-plus/testing/playwright' const errors = Behaviors.consoleErrors(page) // console.error and uncaught exceptions, from now on await Behaviors.neverShows(page, { text: 'Could not load', during: async () => { await page.reload() await page.getByRole('heading').waitFor() }, }) expect(errors()).toEqual([])consoleErrorslists everyerrordiagnostic the default reporter logs, so this test also fails on aMountFailedor aPageContained. A warning is logged withconsole.logand is not listed: to fail on warnings too, give the page a reporter that callsconsole.errorfor them.