-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 / | ||
}); | ||
}); | ||
}); | ||
``` |