Commit 86e84404 authored by Giannis Kepas's avatar Giannis Kepas
Browse files

fix test 37 passing

parent 51527225
Loading
Loading
Loading
Loading
+32 −9
Original line number Diff line number Diff line
@@ -16,16 +16,33 @@ describe('solution_37', () => {

    it('should return a Promise', () => {
      const result = delay(100);
      assert.strictEqual(typeof result.then, 'function');
      assert.ok(
        result instanceof Promise,
        'Result is not a native Promise instance',
      );
    });

    it('should resolve after the specified delay', async () => {
      const start = Date.now();
    it('should not resolve before the specified delay and then resolve after', async () => {
      const promise = delay(200);
      clock.tick(200);
      let settled = false;
      promise.then(() => {
        settled = true;
      });

      // Advance almost all the time but not complete
      clock.tick(199);
      // Flush microtasks
      await Promise.resolve();
      assert.strictEqual(settled, false, 'Promise resolved too early');

      // Complete remaining time
      clock.tick(1);
      await promise;
      const elapsed = Date.now() - start;
      assert(elapsed >= 200, `Elapsed: ${elapsed}`);
      assert.strictEqual(
        settled,
        true,
        'Promise did not resolve after full delay',
      );
    });

    it('should resolve with undefined', async () => {
@@ -36,12 +53,18 @@ describe('solution_37', () => {
    });

    it('should work with zero delay', async () => {
      const start = Date.now();
      const promise = delay(0);
      let settled = false;
      promise.then(() => {
        settled = true;
      });
      clock.tick(0);
      await promise;
      const elapsed = Date.now() - start;
      assert(elapsed < 50, `Elapsed: ${elapsed}`);
      assert.strictEqual(
        settled,
        true,
        'Promise should resolve immediately for 0 delay',
      );
    });

    it('should accept then', (done) => {