Last active
February 18, 2020 14:18
-
-
Save ajcastro/eef037e23b62a083f10d8086e90c4493 to your computer and use it in GitHub Desktop.
Cypress seed api
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
// 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