Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fakerjs in Cypress

I am trying to use fakerjs in my cypress tests to randomly generate fake data for my forms. I have tried exporting it in support/index.js which did not work.

Is there any standard way to add fakerjs to all cypress specs instead of adding it in every spec file?

like image 855
user1614862 Avatar asked Dec 31 '22 14:12

user1614862


1 Answers

First off, what's wrong with importing it in every spec?

That being said, you can do this:

cypress/support/index.js:

cy.faker = require('faker');

your specs:

it(`test`, () => {
    const words = cy.faker.lorem.words();
});
like image 94
dwelle Avatar answered Jan 13 '23 15:01

dwelle