UNPKG

piumino

Version:

Piumino, meaning duvet in Italian, is like a duvet over the bed called Angular TestBed. It provides test helpers to test trivial things like inputs and outputs with a single line.

56 lines (55 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Piumino = void 0; const object_helper_1 = require("./helpers/object.helper"); const base_matcher_1 = require("./matchers/base.matcher"); class Piumino { constructor() { this.fixture = null; } /** * Initialize Piumino. * * @param fixture - The TestBed fixture to use for all expects. */ init(fixture) { this.fixture = fixture; } /** * Select an element that is a child of the fixture's component to expect something on. * * @param selector - The CSS selector to find the element. */ expect(selector) { const errorStack = this.getErrorStack(); return new base_matcher_1.BaseMatcher({ selector, errorStack, getFixture: () => this.getFixture() }); } /** * Replace a function implementation on the provided object with the provided implementation. * * @param obj - The object to replace the function on. * @param func - The name of the function to replace. * @param implementation - The implementation to replace the function with. */ replaceFunction(obj, func, implementation) { object_helper_1.ObjectHelper.replaceFunction(obj, func, implementation); } /** * Restore a function implementation on the provided object with the original implementation.\ * NOTE: Does nothing if the function was never replaced. * * @param obj - The object to restore the function on. * @param func - The name of the function to restore. */ restoreFunction(obj, func) { object_helper_1.ObjectHelper.restoreFunction(obj, func); } getFixture() { return this.fixture; } getErrorStack() { var _a; return (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").filter(item => !item.toLowerCase().includes("piumino")).join("\n"); } } exports.Piumino = Piumino;