UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const matcher_1 = require("./matcher");
4const stringification_1 = require("../stringification");
5class EmptyMatcher extends matcher_1.Matcher {
6 toBeEmpty() {
7 const actualValue = this.actualValue;
8 const length = this._getLength(actualValue);
9 this._registerMatcher((length === 0) === this.shouldMatch, `Expected "${typeof actualValue === "string"
10 ? actualValue
11 : stringification_1.stringify(actualValue)}" ` + `${this.shouldMatch ? "" : "not "}to be empty.`, "value to be empty", {
12 actualLength: length,
13 expectedLength: this.shouldMatch ? 0 : "> 0"
14 });
15 }
16 _getLength(value) {
17 if (value instanceof Map) {
18 return value.size;
19 }
20 if (value.length !== undefined) {
21 return value.length;
22 }
23 return Object.keys(value).length;
24 }
25}
26exports.EmptyMatcher = EmptyMatcher;
27//# sourceMappingURL=empty-matcher.js.map
\No newline at end of file