Skip to content

Instantly share code, notes, and snippets.

@ajcastro
Last active February 18, 2020 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajcastro/eef037e23b62a083f10d8086e90c4493 to your computer and use it in GitHub Desktop.
Save ajcastro/eef037e23b62a083f10d8086e90c4493 to your computer and use it in GitHub Desktop.
Cypress seed api
// cy.seed(...) to call a seeder from api
Cypress.Commands.add('seed', (seeder) => {
// here you will notice that we namespaced our seeders for e2e tests
cy.request('GET', Cypress.config().apiUrl + 'seed?seeder=' + 'Seeds\\E2E\\' + seeder)
})
// routes/web.php
if (app()->environment() !== 'production') {
Route::get('/seed', function ($model) {
\Artisan::call('db:seed', ['--class' => request('seeder')]);
});
}
// Seeds\E2E\Users\UsersPaginationSeeder
class UsersPaginationSeeder extends Seeder {
public function run() {
factory(User::class)->create([
'name' => 'John Doe',
]);
}
}
// Usage:
it('should paginate users', () => {
cy.seed('Users\\UsersPaginationSeeder')
// then assert to see users with given names
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment