How to test with Math.random in JavaScript?

前端 未结 3 797
花落未央
花落未央 2021-01-05 09:21

I have a function that will select a random value between a min and a max value. So when I have a test where I test that the value fall between the min and max value. But as

3条回答
  •  無奈伤痛
    2021-01-05 09:50

    Generally your tests should pass for all possible values of your non-deterministic code. Maybe have a loop in your test where you do the test say 100 times. That will catch more failures without changing the application code. What you suggested is also an option.

提交回复
热议问题