hypertune
Version:
[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt
36 lines (27 loc) • 939 B
text/typescript
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);
});