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

const EXAMPLE_MESSAGE = "Expected value, but got null or undefined";

test("throws on null", () => {
  expect(() => nullThrows(null, EXAMPLE_MESSAGE)).toThrow(EXAMPLE_MESSAGE);
});

test("throws on undefined", () => {
  expect(() => nullThrows(undefined, EXAMPLE_MESSAGE)).toThrow(EXAMPLE_MESSAGE);
});

test.each([
  [[]],
  [["content"]],
  [false],
  [true],
  [0],
  [1],
  [NaN],
  [new Date()],
  [new Date("Not a date string")],
])("returns %s", (value) => {
  expect(nullThrows(value, EXAMPLE_MESSAGE)).toEqual(value);
});
