@better-auth-kit/tests
A collection of utilities to help you test your Better-Auth plugins.
If you're developing a custom plugin for Better-Auth, you may need to test it. This library is intended to provide utilities to help you test your plugins.
This library currently is pulled out from the main Better-Auth package, but is intended to provide more features in the future.
Begin testing!
You can now use the test APIs to test your plugin:
Then, start Vitest!
API
getTestInstance
Optionally takes two arguments, the first is the options for the betterAuth
instance, the second is the options for the test instance itself.
You can configure the betterAuth client instance inside the second argument.
Options
clientOptions
- The options for the Better-Auth client instance.port
- The baseURL port for the better-auth instance.disableTestUser
- Whether to disable the test user.testUser
- The test user to use for the test instance.testWith
- The database to use for the test instance. (sqlite
,postgres
,mongodb
,mysql
)
Methods
client
- The Better-Auth client instance.testUser
- The premade test user.signInWithTestUser
- Sign in with the premade test user.signInWithUser
- Sign in with a custom user.cookieSetter
- Set the cookie for the test instance.customFetchImpl
- The custom fetch implementation for the test instance.sessionSetter
- Set the session for the test instance.
client
The Better-Auth client instance.
testUser
The premade test user.
signInWithTestUser
signInWithUser
cookieSetter
Useful for getting the session of a successful sign in and applying that to a new headers object's cookie.
customFetchImpl
By default, when using the auth client, we make a fetch request to the better-auth server whenever you call an endpoint.
However, you can optionally provide the customFetchImpl
to bypass this and it will skip the fetch request to the better-auth server, and instead directly invoke the endpoint on the server.
sessionSetter
Useful for getting the session from the response of a successful sign in and applying that to a new headers object.
db
The database adapter.