import { expect, test } from "vitest";
import nanThrows from "./nanThrows";

const EXAMPLE_MESSAGE = "Expected a number, but got not a number.";

test("throws on number NaN", () => {
  expect(() => nanThrows(NaN, EXAMPLE_MESSAGE)).toThrow(EXAMPLE_MESSAGE);
});

test("throws on invalid Date", () => {
  expect(() =>
    nanThrows(new Date("Not a date string"), EXAMPLE_MESSAGE)
  ).toThrow(EXAMPLE_MESSAGE);
});

test("returns valid integer", () => {
  expect(nanThrows(123, EXAMPLE_MESSAGE)).toBe(123);
});

test("returns valid float", () => {
  expect(nanThrows(1.23, EXAMPLE_MESSAGE)).toBe(1.23);
});

test("returns positive Infinity", () => {
  expect(nanThrows(Infinity, EXAMPLE_MESSAGE)).toBe(Infinity);
});

test("returns negative Infinity", () => {
  expect(nanThrows(-Infinity, EXAMPLE_MESSAGE)).toBe(-Infinity);
});

test("returns valid Date", () => {
  const d = new Date();
  expect(nanThrows(d, EXAMPLE_MESSAGE)).toBe(d);
});
