From 30972c6d2b8deb2aade4f7868dc5291b0ba7acda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Xalambr=C3=AD?= Date: Fri, 30 Jul 2021 18:41:05 -0500 Subject: [PATCH] Document the MockStrategy --- docs/strategies/mock.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/strategies/mock.md b/docs/strategies/mock.md index 9f230bb..ee7ee65 100644 --- a/docs/strategies/mock.md +++ b/docs/strategies/mock.md @@ -1 +1,42 @@ # MockStrategy + +This strategy is intended to be used for testing purposes only. + +This strategy receives a Response object and it will resolve all authentication requests using a clone of that Response. + +## Create a new instance of MockStrategy + +```ts +import { MockStrategy } from "remix-auth"; +import { Response } from "remix"; + +let strategy = new MockStrategy(new Response(""))); +``` + +## Use the strategy + +```ts +authenticator.use(strategy); +``` + +## Example in a Test + +If you want to test a loader or action that uses an authenticator, you can replace it with the MockStrategy. + +```ts +import { redirect } from "remix"; +import { authenticator } from "./auth.server"; +import { MockStrategy } from "remix-auth"; +import { loader } from "./routes/dashboard"; + +describe("Dashboard", () => { + describe("Loader", () => { + test("should redirect to ", async () => { + authenticator + .unuse("auth0") // remove the strategy you are using + .use(new MockStrategy(redirect("/"))); + // test your loader here which will redirect to / + }); + }); +}); +```