Adonis Sink
Adonis sink contains fake implementations for commonly used AdonisJs providers. You can use this package to write tests for your own providers.
It contains fake implmentations for
- Config provider
- Helpers provider
- Logger provider
- Env provider
- Setup
adonis-fold
resolver.
Config provider
If your provider has a dependency on Config provider, you must use a fake implementation to write tests.
const Config = const test = test
Then inside your Redis
class you can make use of the Config.get
method.
{ const redisConfig = config }
Helpers Provider
Helpers provider is used to get path to certain application directories. All the methods from the actual provider are available in the fake implementation.
const Helpers = const test = const path = test
The Helpers
provider needs the appRoot
as the constructor argument.
Logger Provider
Logger provider is used to log messages. The fake implementation also let you verify whether a message for a given level was logged or not.
const Logger = const test = const path = test
And use it like this
{ thislogger = logger } { if thisconfighost = 'localhost' thislogger }
For complex message, you may use logger.contains
over logger.has
, since logger.has
checks the equality of 2 strings and logger.contains
does a sub string check.
thisloggerthislogger
Env Provider
Also env provider can be used to read environment variables. The fake implementation doesn't load any .env
file, whereas you can set values manually before writing tests.
const Env = const env = env
Resolver Setup
The resolver
is an object to make namespaces and resolve values for a given namespace based upon the directory structure and autoloaded namespace.
Setup of resolver
is done before AdonisJs application boots, but at the time of writing tests, there is no application and hence you can setup the resolver using a pre-configured method.
const setupResolver = test
Now your application code under the test can make use of the adonis-fold
resolver to resolve dependencies.
const resolver = resolver // returns { instance: HomeController, isClosure: false, method: render }