import { delay } from '../src/main';
import { Future, never, reject, fulfill } from '../src/Promise';
import { silenceError, isNever, isRejected, isPending, getValue } from '../src/inspect';
import { assertSame } from './lib/test-util';
import assert from 'assert';

describe('delay', function() {

    it('should be identity for 0 ms', () => {
        let p = fulfill();
        assert.strictEqual(p, delay(0, p));
    });

    it('should be identity for rejected', () => {
        let p = reject();
        silenceError(p);
        assert.strictEqual(p, delay(1, p));
    });

    it('should not delay rejected', () => {
        let p = new Future();
        let d = delay(1, p);

        assert(isPending(d));

        let x = {};
        p._reject(x);

        return d.then(assert.ifError, e => assert.strictEqual(x, e));
    });

    it('should return never for never', () => {
        assert(isNever(delay(0, never())));
    });

    it('should delay value', () => {
        let x = {};
        let t = 10;
        let p = delay(t, x);

        let now = Date.now();
        return assertSame(fulfill(x), p)
            .then(() => assert(Date.now() - now >= t));
    });

    it('should delay fulfilled', () => {
        let x = {};
        let t = 10;
        let p = delay(t, fulfill(x));

        let now = Date.now();
        return assertSame(fulfill(x), p)
            .then(() => assert(Date.now() - now >= t));
    });
});
@@ -260,16 +260,65 @@
 sert';%0A%0A
+function lte(a, b) %7B%0A    return (a - 1) %3C= b;%0A%7D%0A%0A
 describe
@@ -1180,32 +1180,39 @@
 en(() =%3E assert(
+lte(t, 
 Date.now() - now
@@ -1203,37 +1203,33 @@
 Date.now() - now
- %3E= t
+)
 ));%0A    %7D);%0A%0A   
@@ -1447,16 +1447,23 @@
  assert(
+lte(t, 
 Date.now
@@ -1474,13 +1474,9 @@
  now
- %3E= t
+)
 ));%0A

Add epsilon to time comparisons, since JS clock is inaccurate