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.
88 lines (87 loc) • 3.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseMatcher = void 0;
const input_matcher_1 = require("./input.matcher");
const matcher_1 = require("./matcher");
const output_matcher_1 = require("./output.matcher");
class BaseMatcher extends matcher_1.Matcher {
/**
* Select an input of the selected element to expect something on.
*
* @param inputSelector - The selector to find the input.
*/
input(inputSelector) {
return new input_matcher_1.InputMatcher(Object.assign(Object.assign({}, this.state), { inputSelector }));
}
/**
* Select an output of the selected element to expect something on.
*
* @param outputSelector - The selector to find the output.
*/
output(outputSelector) {
return new output_matcher_1.OutputMatcher(Object.assign(Object.assign({}, this.state), { outputSelector }));
}
/**
* Expect the selected element to have the provided text.
*
* @param text - The text to compare with the text of the selected element.
*/
toHaveText(text) {
this.setDescription(`have text '${text}'`);
this.setMatcher(() => {
var _a, _b;
const elementText = (_b = (_a = this.getElement().nativeElement.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
return [elementText === text, elementText, text];
});
return this;
}
/**
* Expect the selected element to have the provided text, ignoring case.
*
* @param text - The text to compare with the text of the selected element.
*/
toHaveTextCaseInsensitive(text) {
this.setDescription(`have case insensitive text '${text.toLowerCase()}'`);
this.setMatcher(() => {
var _a, _b;
const elementText = (_b = (_a = this.getElement().nativeElement.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) !== null && _b !== void 0 ? _b : "";
return [elementText === text.toLowerCase(), elementText, text.toLowerCase()];
});
return this;
}
/**
* Expect the selected element to be present in the DOM.
*/
toBePresent() {
this.setDescription("be present");
this.setMatcher(() => {
var _a;
const element = (_a = this.getElement(false)) === null || _a === void 0 ? void 0 : _a.nativeElement;
return [!!element && element.ownerDocument === element.getRootNode({ composed: true })];
});
return this;
}
/**
* Expect the selected element to be visible in the DOM.
*/
toBeVisible() {
this.setDescription("be visible");
this.setMatcher(() => {
var _a;
const element = (_a = this.getElement(false)) === null || _a === void 0 ? void 0 : _a.nativeElement;
if (!element) {
return [false];
}
const computedStyle = getComputedStyle(element);
const isStyleVisible = computedStyle.display !== "none"
&& computedStyle.visibility !== "hidden"
&& computedStyle.visibility !== "collapsed"
&& computedStyle.opacity !== "0";
const isAttributeVisible = !element.hasAttribute("hidden");
const isInDocument = element.ownerDocument === element.getRootNode({ composed: true });
return [isStyleVisible && isAttributeVisible && isInDocument];
});
return this;
}
}
exports.BaseMatcher = BaseMatcher;