All files / test promise_manual.tsx

90.9% Statements 10/11
66.66% Branches 2/3
100% Functions 4/4
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24      4x     12x 12x 12x 12x       12x   12x 2x   10x          
/*
 * Create a promise that can be resolved manually with data or an error.
 */
export const create = async <T,>(
  resolver: { resolve: boolean },
  dataOrError: Error | T,
): Promise<T> => {
  return new Promise((resolve, reject) => {
    const interval = setInterval(() => {
      Iif (!resolver.resolve) {
        return;
      }
 
      clearInterval(interval);
 
      if (dataOrError instanceof Error) {
        reject(dataOrError);
      } else {
        resolve(dataOrError);
      }
    }, 1000);
  });
};