UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const empty_matcher_1 = require("./empty-matcher");
4const stringification_1 = require("../stringification");
5class StringMatcher extends empty_matcher_1.EmptyMatcher {
6 toMatch(regex) {
7 if (regex === null || regex === undefined) {
8 throw new TypeError("toMatch regular expression must not be null or undefined.");
9 }
10 this._registerMatcher(regex.test(this.actualValue) === this.shouldMatch, `Expected ${stringification_1.stringify(this.actualValue)} ${!this.shouldMatch ? "not " : ""}to conform to ${regex}.`, regex, {
11 string: this.actualValue,
12 regex: regex.toString()
13 });
14 }
15 toContain(expectedContent) {
16 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, {
17 actualContainer: this.actualValue,
18 expectedContent,
19 });
20 }
21}
22exports.StringMatcher = StringMatcher;
23//# sourceMappingURL=string-matcher.js.map
\No newline at end of file