1
0

sleep.spec.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* Import modules. */
  2. const Nito = require('../..')
  3. describe('Utils:sleep', () => {
  4. test('it should wait 1 second for an execution break', async () => {
  5. /* Initialize start time. */
  6. const start = new Date()
  7. /* Wait 1 second. */
  8. await Nito.Utils.sleep(1 * 1000) // 1 second
  9. /* Calculate duration. */
  10. const duration = new Date() - start
  11. /* Evaluate test. */
  12. expect(duration).toBeGreaterThanOrEqual(1 * 1000) // 1 second
  13. expect(duration).toBeLessThanOrEqual(1.5 * 1000) // 1.5 seconds
  14. })
  15. test('it should wait 53seconds for an execution break', async () => {
  16. /* Initialize start time. */
  17. const start = new Date()
  18. /* Wait 1 second. */
  19. await Nito.Utils.sleep(3 * 1000) // 3 seconds
  20. /* Calculate duration. */
  21. const duration = new Date() - start
  22. /* Evaluate test. */
  23. expect(duration).toBeGreaterThanOrEqual(3 * 1000) // 3 seconds
  24. expect(duration).toBeLessThanOrEqual(3.5 * 1000) // 3.5 seconds
  25. })
  26. })