trampoline-ts
Version:
A type-safe way to emulate tail-call optimization with trampolines
36 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const conditional_type_checks_1 = require("conditional-type-checks");
const thunk_1 = require("../src/thunk");
describe('thunk', () => {
describe('isThunk(value)', () => {
it('returns true if the value is a thunk created by this lib', () => {
expect(thunk_1.isThunk(thunk_1.toThunk(() => null))).toBe(true);
});
it('returns false if the value is not a thunk', () => {
expect(thunk_1.isThunk(() => null)).toBe(false);
expect(thunk_1.isThunk(true)).toBe(false);
expect(thunk_1.isThunk(1)).toBe(false);
expect(thunk_1.isThunk('')).toBe(false);
});
});
describe('toThunk', () => {
it('converts a thunk-like function to a thunk', () => {
const thunk = thunk_1.toThunk(() => 'some value');
expect(thunk).toHaveProperty('__THUNK__', thunk_1.THUNK_SYMBOL);
expect(thunk()).toBe('some value');
});
});
describe('UnwrapThunk<T>', () => {
it('removes recursively removes all instances of Thunk<T> from T', () => {
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
conditional_type_checks_1.assert(true);
});
});
});
//# sourceMappingURL=thunk.spec.js.map