factories
Introduction
Factories are simple helpers to allow you to create records in your database in testing environments. Light's factories work in a similar way in that they are a wrapper over whatever ORM you choose.
Example
factories/user.js
The factory requires a name and a function that returns whatever methods you would like to make available.
Usage
Inside of tests, you can then import the factory and create the database records.
routes/__tests__/index.js
Similar to the models, light exports both the methods you provide as well as the same methods with the factory name appended. I.e. you can use create
or createUser
and they will do the same thing. The benefit of using createUser
over create
is that it will allow you to import multiple factories with create
methods without the names colliding.
Last updated