Integrating ChanceJS into your tests

Randomizing input data

Integrating ChanceJS into your tests

Minimalist generator of random data

Chance is open source software that can be easily integrated into Cypress tests. Ideal for generating random data in tests where it is critical not to have same input every time.

It is pretty straightforward to use. For example, if we want to create a random e-mail address and use it as input date, we can do that simply with:

chance.email()
=> 'kawip@piklojzob.gov'

If you need to use specific domain:

chance.email({domain: 'example.com'})
=> 'giigjom@example.com'

When you need to generate lorem-ipsum-like text, use:

chance.paragraph();
=> 'Lel fi huepe jupu akse zej ire vesik kojvulom zon is biwuwkef pa. Uv hokivej voh ebu numdogi akolo hik uwlez ta vacev ofdaimi acunetum suvet uhdab ir soglazo ju pafbeb. Pub cezeh fuc kebamnul he ok luumoabi rawkig me fov pin zup biv risugra. Ralpunad apkomgib alnirciw akel wa lus wahfum burog buol vecotihe abadahoj ugolo wovki ucojal fec.'

Of course, you can limit the number of sentences in it:

chance.paragraph({ sentences: 1 });
 => 'Idefeulo foc omoemowa wahteze liv juvde puguprof epehuji upuga zige odfe igo sit pilamhul oto ukurecef.'

You can generate any kind of number, for example an integer

chance.integer();
=> 1293235

You can limit that as well:

chance.integer({ min: -20, max: 20 })
=> -7

Any of these can be stored in variables in tests and reused multiple times. There are many more examples, make sure you check it out.


    tools