tsoid
Version:
Typed functional library to deal with async operations.
28 lines (27 loc) • 1.59 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const flatMap_1 = require("../flatMap");
describe('flatMap', () => {
it('Should flat a promise and apply the mapper function successfully', () => __awaiter(void 0, void 0, void 0, function* () {
const p = () => Promise.resolve(42);
const doubleP = (x) => Promise.resolve(x * 2);
const result = yield flatMap_1.default(p, doubleP);
expect(result).toBe(84);
}));
it('Should propagate error if it occurs', () => __awaiter(void 0, void 0, void 0, function* () {
const p = () => Promise.reject(new Error('Could not resolve the promise'));
const doubleP = (x) => Promise.resolve(x * 2);
const result = yield flatMap_1.default(p, doubleP);
expect(result).toBeInstanceOf(Error);
expect(result.message).toBe('Could not resolve the promise');
}));
});