File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,36 @@ re-use existing objects internally as a minor performance optimization.
233233| ` ctx.basePath ` | ` ctx.config.basePath ` |
234234| ` ctx.remoteAddr ` | ` ctx.info.remoteAddr ` |
235235
236+ ## ` createHandler `
237+
238+ The ` createHandler ` function was often used to launch Fresh for tests. This can
239+ be now done via the [ ` Builder ` ] ( /docs/canary/concepts/builder ) .
240+
241+ ``` ts
242+ // Best to do this once instead of for every test case for
243+ // performance reasons.
244+ const builder = new Builder ();
245+ const applySnapshot = await builder .build ({ snapshot: " memory" });
246+
247+ function testApp() {
248+ const app = new App ()
249+ .get (" /" , () => new Response (" hello" ));
250+ // Applies build snapshot to this app instance.
251+ applySnapshot (app );
252+ }
253+
254+ Deno .test (" My Test" , () => {
255+ const handler = testApp ().handler ();
256+
257+ const response = await handler (new Request (" http://localhost" ));
258+ const text = await response .text ();
259+
260+ if (text !== " hello" ) {
261+ throw new Error (" fail" );
262+ }
263+ });
264+ ```
265+
236266## Getting help
237267
238268If you run into problems with upgrading your app, reach out to us by creating an
You can’t perform that action at this time.
0 commit comments