type-fns
Version:
A set of types, type checks, and type guards for simpler, safer, and easier to read code.
38 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const isOfEnum_1 = require("./isOfEnum");
describe('isOfEnum', () => {
let Planet;
(function (Planet) {
Planet["VENUS"] = "VENUS";
Planet["EARTH"] = "EARTH";
Planet["MARS"] = "MARS";
})(Planet || (Planet = {}));
it('can be used to assess correctly, default call', () => {
const isPlanet = (0, isOfEnum_1.createIsOfEnum)(Planet);
const earthIsPlanet = isPlanet('EARTH');
const plutoIsPlanet = isPlanet('PLUTO');
expect(earthIsPlanet).toEqual(true);
expect(plutoIsPlanet).toEqual(false);
});
it('can be used to assess correctly, named call', () => {
const isPlanet = (0, isOfEnum_1.createIsOfEnum)(Planet);
const earthIsPlanet = isPlanet.assess('EARTH');
const plutoIsPlanet = isPlanet.assess('PLUTO');
expect(earthIsPlanet).toEqual(true);
expect(plutoIsPlanet).toEqual(false);
});
it('can be used to create type guarded branches', () => {
const isPlanet = (0, isOfEnum_1.createIsOfEnum)(Planet);
const earth = 'EARTH';
if (isPlanet.assess(earth)) {
const home = earth; // no type error
}
});
it('can be used to create type asserted casts', () => {
const isPlanet = (0, isOfEnum_1.createIsOfEnum)(Planet);
const earth = 'EARTH';
const home = isPlanet.assure(earth);
});
});
//# sourceMappingURL=isOfEnum.test.js.map