UNPKG

alsatian

Version:

TypeScript and JavaScript testing framework for beautiful and readable tests

23 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const empty_matcher_1 = require("./empty-matcher"); const stringification_1 = require("../stringification"); class StringMatcher extends empty_matcher_1.EmptyMatcher { toMatch(regex) { if (regex === null || regex === undefined) { throw new TypeError("toMatch regular expression must not be null or undefined."); } this._registerMatcher(regex.test(this.actualValue) === this.shouldMatch, `Expected ${stringification_1.stringify(this.actualValue)} ${!this.shouldMatch ? "not " : ""}to conform to ${regex}.`, regex, { string: this.actualValue, regex: regex.toString() }); } toContain(expectedContent) { this._registerMatcher(this.actualValue.indexOf(expectedContent) > -1 === this.shouldMatch, `Expected ${stringification_1.stringify(this.actualValue)} ${!this.shouldMatch ? "not " : ""}` + `to contain ${stringification_1.stringify(expectedContent)}.`, expectedContent, { actualContainer: this.actualValue, expectedContent, }); } } exports.StringMatcher = StringMatcher; //# sourceMappingURL=string-matcher.js.map