146 lines
3.5 KiB
JavaScript
146 lines
3.5 KiB
JavaScript
import { getBoolFromString } from "./boolean-helper";
|
|
|
|
describe("getBoolFromString", () => {
|
|
describe("Happy paths", () => {
|
|
test('"true" -> true', () => {
|
|
const input = "true";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(true);
|
|
});
|
|
|
|
test('"false" -> false', () => {
|
|
const input = "false";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test('"other string" -> false', () => {
|
|
const input = "some random value";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Capitalization", () => {
|
|
test('"TRUE" -> true', () => {
|
|
const input = "TRUE";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(true);
|
|
});
|
|
|
|
test('"True" -> true', () => {
|
|
const input = "True";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(true);
|
|
});
|
|
|
|
test('"FALSE" -> false', () => {
|
|
const input = "FALSE";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test('"False" -> false', () => {
|
|
const input = "False";
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Graceful type errors", () => {
|
|
describe("Boolean", () => {
|
|
test("true -> true", () => {
|
|
const input = true;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(true);
|
|
});
|
|
|
|
test("false -> false", () => {
|
|
const input = false;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Empty", () => {
|
|
test("undefined -> false", () => {
|
|
const input = undefined;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test("null -> false", () => {
|
|
const input = null;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test("{} -> false", () => {
|
|
const input = {};
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Other types", () => {
|
|
test("1 -> false", () => {
|
|
const input = 1;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test("Object -> false", () => {
|
|
const input = {
|
|
test: true,
|
|
true: true,
|
|
};
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test("function -> false", () => {
|
|
const input = () => true;
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
|
|
test("array -> false", () => {
|
|
const input = [true];
|
|
|
|
const output = getBoolFromString(input);
|
|
|
|
expect(output).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
});
|