@plugjs/expect5 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -1
- package/dist/expectation/async.cjs +73 -0
- package/dist/expectation/async.cjs.map +6 -0
- package/dist/expectation/async.d.ts +54 -0
- package/dist/expectation/async.mjs +46 -0
- package/dist/expectation/async.mjs.map +6 -0
- package/dist/expectation/basic.cjs +155 -183
- package/dist/expectation/basic.cjs.map +1 -1
- package/dist/expectation/basic.d.ts +90 -47
- package/dist/expectation/basic.mjs +142 -163
- package/dist/expectation/basic.mjs.map +1 -1
- package/dist/expectation/diff.cjs +7 -7
- package/dist/expectation/diff.cjs.map +1 -1
- package/dist/expectation/diff.mjs +7 -7
- package/dist/expectation/diff.mjs.map +1 -1
- package/dist/expectation/expect.cjs +94 -108
- package/dist/expectation/expect.cjs.map +2 -2
- package/dist/expectation/expect.d.ts +103 -130
- package/dist/expectation/expect.mjs +131 -137
- package/dist/expectation/expect.mjs.map +2 -2
- package/dist/expectation/include.cjs +50 -61
- package/dist/expectation/include.cjs.map +1 -1
- package/dist/expectation/include.d.ts +19 -10
- package/dist/expectation/include.mjs +53 -57
- package/dist/expectation/include.mjs.map +1 -1
- package/dist/expectation/throwing.cjs +27 -27
- package/dist/expectation/throwing.cjs.map +1 -1
- package/dist/expectation/throwing.d.ts +36 -8
- package/dist/expectation/throwing.mjs +26 -26
- package/dist/expectation/throwing.mjs.map +1 -1
- package/dist/expectation/trivial.cjs +96 -0
- package/dist/expectation/trivial.cjs.map +6 -0
- package/dist/expectation/trivial.d.ts +13 -0
- package/dist/expectation/trivial.mjs +61 -0
- package/dist/expectation/trivial.mjs.map +6 -0
- package/dist/expectation/types.cjs +9 -12
- package/dist/expectation/types.cjs.map +1 -1
- package/dist/expectation/types.d.ts +52 -10
- package/dist/expectation/types.mjs +8 -10
- package/dist/expectation/types.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/expectation/async.ts +151 -0
- package/src/expectation/basic.ts +360 -156
- package/src/expectation/diff.ts +8 -9
- package/src/expectation/expect.ts +239 -268
- package/src/expectation/include.ts +93 -59
- package/src/expectation/throwing.ts +102 -41
- package/src/expectation/trivial.ts +107 -0
- package/src/expectation/types.ts +82 -25
- package/src/index.ts +2 -0
- package/dist/expectation/void.cjs +0 -111
- package/dist/expectation/void.cjs.map +0 -6
- package/dist/expectation/void.d.ts +0 -39
- package/dist/expectation/void.mjs +0 -77
- package/dist/expectation/void.mjs.map +0 -6
- package/src/expectation/void.ts +0 -80
|
@@ -1,153 +1,146 @@
|
|
|
1
1
|
// expectation/expect.ts
|
|
2
|
-
import { ExpectationError, matcherMarker } from "./types.mjs";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
toBeRejected,
|
|
4
|
+
toBeRejectedWithError,
|
|
5
|
+
toBeResolved
|
|
6
|
+
} from "./async.mjs";
|
|
7
|
+
import {
|
|
8
|
+
toBeA,
|
|
9
|
+
toBeCloseTo,
|
|
10
|
+
toBeError,
|
|
11
|
+
toBeGreaterThan,
|
|
12
|
+
toBeGreaterThanOrEqual,
|
|
13
|
+
toBeInstanceOf,
|
|
14
|
+
toBeLessThan,
|
|
15
|
+
toBeLessThanOrEqual,
|
|
16
|
+
toBeWithinRange,
|
|
17
|
+
toEqual,
|
|
18
|
+
toHaveLength,
|
|
19
|
+
toHaveProperty,
|
|
20
|
+
toHaveSize,
|
|
21
|
+
toMatch,
|
|
22
|
+
toStrictlyEqual
|
|
19
23
|
} from "./basic.mjs";
|
|
20
24
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
toInclude,
|
|
26
|
+
toMatchContents
|
|
23
27
|
} from "./include.mjs";
|
|
24
28
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
toThrow,
|
|
30
|
+
toThrowError
|
|
27
31
|
} from "./throwing.mjs";
|
|
28
32
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
toBeDefined,
|
|
34
|
+
toBeFalse,
|
|
35
|
+
toBeFalsy,
|
|
36
|
+
toBeNaN,
|
|
37
|
+
toBeNegativeInfinity,
|
|
38
|
+
toBeNull,
|
|
39
|
+
toBeNullable,
|
|
40
|
+
toBePositiveInfinity,
|
|
41
|
+
toBeTrue,
|
|
42
|
+
toBeTruthy,
|
|
43
|
+
toBeUndefined
|
|
44
|
+
} from "./trivial.mjs";
|
|
45
|
+
import {
|
|
46
|
+
ExpectationError,
|
|
47
|
+
matcherMarker
|
|
48
|
+
} from "./types.mjs";
|
|
49
|
+
var asyncExpectations = {
|
|
50
|
+
toBeResolved,
|
|
51
|
+
toBeRejected,
|
|
52
|
+
toBeRejectedWithError
|
|
53
|
+
};
|
|
54
|
+
var syncExpectations = {
|
|
55
|
+
// basic
|
|
56
|
+
toBeA,
|
|
57
|
+
toBeCloseTo,
|
|
58
|
+
toBeError,
|
|
59
|
+
toBeGreaterThan,
|
|
60
|
+
toBeGreaterThanOrEqual,
|
|
61
|
+
toBeInstanceOf,
|
|
62
|
+
toBeLessThan,
|
|
63
|
+
toBeLessThanOrEqual,
|
|
64
|
+
toBeWithinRange,
|
|
65
|
+
toEqual,
|
|
66
|
+
toHaveLength,
|
|
67
|
+
toHaveProperty,
|
|
68
|
+
toHaveSize,
|
|
69
|
+
toMatch,
|
|
70
|
+
toStrictlyEqual,
|
|
57
71
|
// include
|
|
58
|
-
toInclude
|
|
59
|
-
toMatchContents
|
|
72
|
+
toInclude,
|
|
73
|
+
toMatchContents,
|
|
60
74
|
// throwing
|
|
61
|
-
toThrow
|
|
62
|
-
toThrowError
|
|
63
|
-
//
|
|
64
|
-
toBeDefined
|
|
65
|
-
toBeFalse
|
|
66
|
-
toBeFalsy
|
|
67
|
-
toBeNaN
|
|
68
|
-
toBeNegativeInfinity
|
|
69
|
-
toBeNull
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
toThrow,
|
|
76
|
+
toThrowError,
|
|
77
|
+
// trivial
|
|
78
|
+
toBeDefined,
|
|
79
|
+
toBeFalse,
|
|
80
|
+
toBeFalsy,
|
|
81
|
+
toBeNaN,
|
|
82
|
+
toBeNegativeInfinity,
|
|
83
|
+
toBeNull,
|
|
84
|
+
toBeNullable,
|
|
85
|
+
toBePositiveInfinity,
|
|
86
|
+
toBeTrue,
|
|
87
|
+
toBeTruthy,
|
|
88
|
+
toBeUndefined
|
|
74
89
|
};
|
|
75
|
-
var
|
|
76
|
-
|
|
90
|
+
var allExpectations = {
|
|
91
|
+
...asyncExpectations,
|
|
92
|
+
...syncExpectations
|
|
93
|
+
};
|
|
94
|
+
var ExpectationsContextImpl = class {
|
|
95
|
+
constructor(value, negative, expects, negated, parent) {
|
|
77
96
|
this.value = value;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
this._negative = false;
|
|
84
|
-
this._positiveExpectations = this;
|
|
85
|
-
this._negativeExpectations = new ExpectationsImpl(value, this);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
_positiveExpectations;
|
|
89
|
-
_negativeExpectations;
|
|
90
|
-
_negative;
|
|
91
|
-
/* == NEW EXPECTATIONS ==================================================== */
|
|
92
|
-
forProperty(prop) {
|
|
93
|
-
this.toBeDefined();
|
|
94
|
-
const child = new ExpectationsImpl(this.value[prop]);
|
|
95
|
-
child.parent = { context: this, prop };
|
|
96
|
-
return child;
|
|
97
|
+
this.negative = negative;
|
|
98
|
+
this.expects = expects;
|
|
99
|
+
this.negated = negated;
|
|
100
|
+
this.parent = parent;
|
|
97
101
|
}
|
|
98
102
|
forValue(value) {
|
|
99
103
|
return new ExpectationsImpl(value);
|
|
100
104
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return this._negative ? this._positiveExpectations : this._negativeExpectations;
|
|
107
|
-
}
|
|
108
|
-
/* == ASYNCHRONOUS EXPECTATIONS =========================================== */
|
|
109
|
-
toBeResolved(assert) {
|
|
110
|
-
return Promise.resolve().then(() => {
|
|
111
|
-
this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
112
|
-
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
113
|
-
}).then(([settlement]) => {
|
|
114
|
-
if (settlement.status === "fulfilled") {
|
|
115
|
-
if (this._negative)
|
|
116
|
-
throw new ExpectationError(this, true, "to be resolved");
|
|
117
|
-
if (assert)
|
|
118
|
-
assert(new ExpectationsImpl(settlement.value));
|
|
119
|
-
} else if (!this._negative) {
|
|
120
|
-
throw new ExpectationError(this, false, "to be resolved");
|
|
121
|
-
}
|
|
122
|
-
return this._positiveExpectations;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
toBeRejected(assert) {
|
|
126
|
-
return Promise.resolve().then(() => {
|
|
127
|
-
this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
128
|
-
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
129
|
-
}).then(([settlement]) => {
|
|
130
|
-
if (settlement.status === "rejected") {
|
|
131
|
-
if (this._negative)
|
|
132
|
-
throw new ExpectationError(this, true, "to be rejected");
|
|
133
|
-
if (assert)
|
|
134
|
-
assert(new ExpectationsImpl(settlement.reason));
|
|
135
|
-
} else if (!this._negative) {
|
|
136
|
-
throw new ExpectationError(this, false, "to be rejected");
|
|
137
|
-
}
|
|
138
|
-
return this._positiveExpectations;
|
|
139
|
-
});
|
|
105
|
+
forProperty(prop) {
|
|
106
|
+
this.expects.toBeDefined();
|
|
107
|
+
const value = this.value[prop];
|
|
108
|
+
const parent = { context: this, prop };
|
|
109
|
+
return new ExpectationsImpl(value, parent);
|
|
140
110
|
}
|
|
141
|
-
|
|
142
|
-
|
|
111
|
+
};
|
|
112
|
+
var ExpectationsImpl = class {
|
|
113
|
+
_context;
|
|
114
|
+
value;
|
|
115
|
+
not;
|
|
116
|
+
constructor(value, parent, positives) {
|
|
117
|
+
this.value = value;
|
|
118
|
+
if (positives) {
|
|
119
|
+
this.not = positives;
|
|
120
|
+
this._context = new ExpectationsContextImpl(
|
|
121
|
+
value,
|
|
122
|
+
true,
|
|
123
|
+
positives,
|
|
124
|
+
this,
|
|
125
|
+
parent
|
|
126
|
+
);
|
|
127
|
+
} else {
|
|
128
|
+
this._context = new ExpectationsContextImpl(
|
|
129
|
+
value,
|
|
130
|
+
false,
|
|
131
|
+
this,
|
|
132
|
+
this,
|
|
133
|
+
parent
|
|
134
|
+
);
|
|
135
|
+
this.not = new ExpectationsImpl(value, parent, this);
|
|
136
|
+
}
|
|
143
137
|
}
|
|
144
138
|
static {
|
|
145
|
-
for (const [key, value] of Object.entries(
|
|
139
|
+
for (const [key, value] of Object.entries(allExpectations)) {
|
|
146
140
|
const expectation = value;
|
|
147
141
|
const fn = function(...args) {
|
|
148
142
|
try {
|
|
149
|
-
expectation.
|
|
150
|
-
return this._positiveExpectations;
|
|
143
|
+
return expectation.call(this._context, ...args);
|
|
151
144
|
} catch (error) {
|
|
152
145
|
if (error instanceof ExpectationError)
|
|
153
146
|
Error.captureStackTrace(error, fn);
|
|
@@ -159,7 +152,7 @@ var ExpectationsImpl = class {
|
|
|
159
152
|
}
|
|
160
153
|
}
|
|
161
154
|
};
|
|
162
|
-
var
|
|
155
|
+
var MatcherImpl = class {
|
|
163
156
|
_matchers;
|
|
164
157
|
_positiveBuilder;
|
|
165
158
|
_negativeBuilder;
|
|
@@ -173,24 +166,25 @@ var ExpectationsMatcherImpl = class {
|
|
|
173
166
|
} else {
|
|
174
167
|
this._negative = false;
|
|
175
168
|
this._positiveBuilder = this;
|
|
176
|
-
this._negativeBuilder = new
|
|
169
|
+
this._negativeBuilder = new MatcherImpl(this._matchers, this);
|
|
177
170
|
}
|
|
178
171
|
}
|
|
179
172
|
get not() {
|
|
180
173
|
return this._negative ? this._positiveBuilder : this._negativeBuilder;
|
|
181
174
|
}
|
|
182
175
|
expect(value) {
|
|
183
|
-
const
|
|
176
|
+
const expectations = expect(value);
|
|
184
177
|
for (const [expectation, negative, args] of this._matchers) {
|
|
185
|
-
|
|
178
|
+
const expect2 = negative ? expectations.not : expectations;
|
|
179
|
+
expect2[expectation](...args);
|
|
186
180
|
}
|
|
187
181
|
}
|
|
188
182
|
static {
|
|
189
183
|
Object.defineProperty(this.prototype, matcherMarker, { value: matcherMarker });
|
|
190
|
-
for (const key in
|
|
184
|
+
for (const key in syncExpectations) {
|
|
191
185
|
Object.defineProperty(this.prototype, key, {
|
|
192
186
|
value: function(...args) {
|
|
193
|
-
return new
|
|
187
|
+
return new MatcherImpl([
|
|
194
188
|
...this._matchers,
|
|
195
189
|
[key, this._negative, args]
|
|
196
190
|
]);
|
|
@@ -203,12 +197,12 @@ var expect = (value) => {
|
|
|
203
197
|
return new ExpectationsImpl(value);
|
|
204
198
|
};
|
|
205
199
|
Object.defineProperty(expect, "not", {
|
|
206
|
-
get: () => new
|
|
200
|
+
get: () => new MatcherImpl([]).not
|
|
207
201
|
});
|
|
208
|
-
for (const name in
|
|
202
|
+
for (const name in syncExpectations) {
|
|
209
203
|
Object.defineProperty(expect, name, {
|
|
210
204
|
value: function(...args) {
|
|
211
|
-
const builder = new
|
|
205
|
+
const builder = new MatcherImpl([]);
|
|
212
206
|
return builder[name](...args);
|
|
213
207
|
}
|
|
214
208
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/expect.ts"],
|
|
4
|
-
"mappings": ";AAAA,
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAWP,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,mBAAmB;AAAA;AAAA,EAEvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,kBAAkB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ClC,OAAO,YAAY,MAAuB;AACxC,YAAM,UAAU,IAAI,YAAY,CAAC,CAAC;AAClC,aAAQ,QAAgB,IAAI,EAAE,GAAG,IAAI;AAAA,IACvC;AAAA,EACF,CAAC;AACH;",
|
|
5
|
+
"names": ["expect"]
|
|
6
6
|
}
|
|
@@ -20,59 +20,51 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// expectation/include.ts
|
|
21
21
|
var include_exports = {};
|
|
22
22
|
__export(include_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
includesMappings: () => includesMappings,
|
|
26
|
-
includesProps: () => includesProps,
|
|
27
|
-
includesValues: () => includesValues
|
|
23
|
+
toInclude: () => toInclude,
|
|
24
|
+
toMatchContents: () => toMatchContents
|
|
28
25
|
});
|
|
29
26
|
module.exports = __toCommonJS(include_exports);
|
|
30
27
|
var import_diff = require("./diff.cjs");
|
|
31
28
|
var import_types = require("./types.cjs");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expected = new Set(contents);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throw new import_types.ExpectationError(context, false, "to be an iterable object");
|
|
54
|
-
}
|
|
55
|
-
const result = (0, import_diff.diff)(actual, expected);
|
|
56
|
-
delete result.error;
|
|
57
|
-
if (result.diff === negative)
|
|
58
|
-
return;
|
|
59
|
-
throw new import_types.ExpectationError(
|
|
60
|
-
context,
|
|
61
|
-
negative,
|
|
62
|
-
`to match contents of ${(0, import_types.stringifyObjectType)(contents)}`,
|
|
63
|
-
{ ...result, value: context.value }
|
|
64
|
-
);
|
|
29
|
+
function toInclude(expected) {
|
|
30
|
+
if (expected instanceof Map)
|
|
31
|
+
return includesMappings(this, expected);
|
|
32
|
+
if (expected instanceof Set)
|
|
33
|
+
return includesValues(this, expected);
|
|
34
|
+
if (Array.isArray(expected))
|
|
35
|
+
return includesValues(this, new Set(expected));
|
|
36
|
+
if (expected instanceof Object)
|
|
37
|
+
return includesProps(this, expected);
|
|
38
|
+
throw new TypeError(`Invalid type for "toInclude(...)": ${(0, import_types.stringifyValue)(expected)}`);
|
|
39
|
+
}
|
|
40
|
+
function toMatchContents(contents) {
|
|
41
|
+
let actual;
|
|
42
|
+
let expected;
|
|
43
|
+
try {
|
|
44
|
+
actual = new Set(this.value);
|
|
45
|
+
expected = new Set(contents);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new import_types.ExpectationError(this, "to be an iterable object", false);
|
|
65
48
|
}
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
const result = (0, import_diff.diff)(actual, expected);
|
|
50
|
+
delete result.error;
|
|
51
|
+
if (result.diff === this.negative)
|
|
52
|
+
return this.expects;
|
|
53
|
+
throw new import_types.ExpectationError(
|
|
54
|
+
this,
|
|
55
|
+
`to match contents of ${(0, import_types.stringifyObjectType)(contents)}`,
|
|
56
|
+
{ ...result, value: this.value }
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function includesProps(context, expected) {
|
|
68
60
|
if (context.value instanceof Map) {
|
|
69
|
-
return includesMappings(context,
|
|
61
|
+
return includesMappings(context, new Map(Object.entries(expected)));
|
|
70
62
|
}
|
|
71
|
-
context.toBeInstanceOf(Object);
|
|
63
|
+
context.expects.toBeInstanceOf(Object);
|
|
72
64
|
const actual = context.value;
|
|
73
65
|
const keys = new Set(Object.keys(expected));
|
|
74
66
|
const props = {};
|
|
75
|
-
if (negative) {
|
|
67
|
+
if (context.negative) {
|
|
76
68
|
for (const key of keys) {
|
|
77
69
|
if (actual[key] !== void 0 || key in actual) {
|
|
78
70
|
props[key] = { diff: true, extra: actual[key] };
|
|
@@ -94,22 +86,22 @@ function includesProps(context, negative, expected) {
|
|
|
94
86
|
}
|
|
95
87
|
const count = Object.keys(props).length;
|
|
96
88
|
if (count === 0)
|
|
97
|
-
return;
|
|
89
|
+
return context.expects;
|
|
98
90
|
const type = count === 1 ? "property" : "properties";
|
|
99
|
-
throw new import_types.ExpectationError(context,
|
|
91
|
+
throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
|
|
100
92
|
diff: true,
|
|
101
93
|
value: actual,
|
|
102
94
|
props
|
|
103
95
|
});
|
|
104
96
|
}
|
|
105
|
-
function includesValues(context,
|
|
106
|
-
context.toBeInstanceOf(Object);
|
|
97
|
+
function includesValues(context, expected) {
|
|
98
|
+
context.expects.toBeInstanceOf(Object);
|
|
107
99
|
if (typeof context.value[Symbol.iterator] !== "function") {
|
|
108
|
-
throw new import_types.ExpectationError(context,
|
|
100
|
+
throw new import_types.ExpectationError(context, "to be an iterable object", false);
|
|
109
101
|
}
|
|
110
102
|
const actual = new Set(context.value);
|
|
111
103
|
const values = [];
|
|
112
|
-
if (negative) {
|
|
104
|
+
if (context.negative) {
|
|
113
105
|
for (const exp of expected) {
|
|
114
106
|
for (const act of actual) {
|
|
115
107
|
const result = (0, import_diff.diff)(act, exp);
|
|
@@ -136,20 +128,20 @@ function includesValues(context, negative, expected) {
|
|
|
136
128
|
}
|
|
137
129
|
const count = values.length;
|
|
138
130
|
if (count === 0)
|
|
139
|
-
return;
|
|
131
|
+
return context.expects;
|
|
140
132
|
const type = count === 1 ? "value" : "values";
|
|
141
|
-
throw new import_types.ExpectationError(context,
|
|
133
|
+
throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
|
|
142
134
|
diff: true,
|
|
143
135
|
value: context.value,
|
|
144
136
|
values
|
|
145
137
|
});
|
|
146
138
|
}
|
|
147
|
-
function includesMappings(context,
|
|
148
|
-
context.toBeInstanceOf(Map);
|
|
139
|
+
function includesMappings(context, expected) {
|
|
140
|
+
context.expects.toBeInstanceOf(Map);
|
|
149
141
|
const actual = context.value;
|
|
150
142
|
const keys = new Set(expected.keys());
|
|
151
143
|
const mappings = [];
|
|
152
|
-
if (negative) {
|
|
144
|
+
if (context.negative) {
|
|
153
145
|
for (const key of keys) {
|
|
154
146
|
if (actual.has(key)) {
|
|
155
147
|
mappings.push([key, { diff: true, extra: actual.get(key) }]);
|
|
@@ -168,9 +160,9 @@ function includesMappings(context, negative, expected) {
|
|
|
168
160
|
}
|
|
169
161
|
const count = mappings.length;
|
|
170
162
|
if (count === 0)
|
|
171
|
-
return;
|
|
163
|
+
return context.expects;
|
|
172
164
|
const type = count === 1 ? "mapping" : "mappings";
|
|
173
|
-
throw new import_types.ExpectationError(context,
|
|
165
|
+
throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
|
|
174
166
|
diff: true,
|
|
175
167
|
value: context.value,
|
|
176
168
|
mappings
|
|
@@ -178,10 +170,7 @@ function includesMappings(context, negative, expected) {
|
|
|
178
170
|
}
|
|
179
171
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
172
|
0 && (module.exports = {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
includesMappings,
|
|
184
|
-
includesProps,
|
|
185
|
-
includesValues
|
|
173
|
+
toInclude,
|
|
174
|
+
toMatchContents
|
|
186
175
|
});
|
|
187
176
|
//# sourceMappingURL=include.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/include.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,mBAIO;AAkBP,SAAS,UAEL,UAKY;AAEd,MAAI,oBAAoB;AAAK,WAAO,iBAAiB,MAAM,QAAQ;AACnE,MAAI,oBAAoB;AAAK,WAAO,eAAe,MAAM,QAAQ;A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@ -1,10 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/** Expect the value to include _all_ properties from the specified _object_. */
|
|
2
|
+
declare function toInclude<T, P extends Record<string, any>>(this: T, properties: P): T;
|
|
3
|
+
/** Expect the value to include _all_ mappings from the specified {@link Map}. */
|
|
4
|
+
declare function toInclude<T>(this: T, mappings: Map<any, any>): T;
|
|
5
|
+
/** Expect the value to include _all_ values from the specified {@link Set}. */
|
|
6
|
+
declare function toInclude<T>(this: T, entries: Set<any>): T;
|
|
7
|
+
/** Expect the value to include _all_ values in any order from the specified _array_. */
|
|
8
|
+
declare function toInclude<T>(this: T, values: any[]): T;
|
|
9
|
+
/**
|
|
10
|
+
* Expect the value to include _all_ values (and only those values, in any
|
|
11
|
+
* order) from the specified _array_.
|
|
12
|
+
*/
|
|
13
|
+
declare function toMatchContents<T>(this: T, contents: any[]): T;
|
|
14
|
+
/**
|
|
15
|
+
* Expect the value to include _all_ values (and only those values, in any
|
|
16
|
+
* order) from the specified {@link Set}.
|
|
17
|
+
*/
|
|
18
|
+
declare function toMatchContents<T>(this: T, contents: Set<any>): T;
|
|
19
|
+
export { toInclude, toMatchContents, };
|