dimanche 21 décembre 2014

Jest: Testing random position of an array

After some research, I found out that mocking will allow me to test random values. However, how do I test the value of a random position (needle) picked up on an array (haystack)?


For instance, how do you test this code with Jest?



var words = ['Hey', 'Hello', 'Hi'];
var random = Math.floor( Math.random() * (words.length - 1) + 0 );
var word = words[random];

Aucun commentaire:

Enregistrer un commentaire