@plugjs/expect5 0.4.2 → 0.4.3

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.
Files changed (59) hide show
  1. package/dist/cli.mjs +1 -1
  2. package/dist/expectation/async.cjs +73 -0
  3. package/dist/expectation/async.cjs.map +6 -0
  4. package/dist/expectation/async.d.ts +54 -0
  5. package/dist/expectation/async.mjs +46 -0
  6. package/dist/expectation/async.mjs.map +6 -0
  7. package/dist/expectation/basic.cjs +155 -183
  8. package/dist/expectation/basic.cjs.map +1 -1
  9. package/dist/expectation/basic.d.ts +90 -47
  10. package/dist/expectation/basic.mjs +142 -163
  11. package/dist/expectation/basic.mjs.map +1 -1
  12. package/dist/expectation/diff.cjs +7 -7
  13. package/dist/expectation/diff.cjs.map +1 -1
  14. package/dist/expectation/diff.mjs +7 -7
  15. package/dist/expectation/diff.mjs.map +1 -1
  16. package/dist/expectation/expect.cjs +94 -108
  17. package/dist/expectation/expect.cjs.map +2 -2
  18. package/dist/expectation/expect.d.ts +103 -130
  19. package/dist/expectation/expect.mjs +131 -137
  20. package/dist/expectation/expect.mjs.map +2 -2
  21. package/dist/expectation/include.cjs +50 -61
  22. package/dist/expectation/include.cjs.map +1 -1
  23. package/dist/expectation/include.d.ts +19 -10
  24. package/dist/expectation/include.mjs +53 -57
  25. package/dist/expectation/include.mjs.map +1 -1
  26. package/dist/expectation/throwing.cjs +27 -27
  27. package/dist/expectation/throwing.cjs.map +1 -1
  28. package/dist/expectation/throwing.d.ts +36 -8
  29. package/dist/expectation/throwing.mjs +26 -26
  30. package/dist/expectation/throwing.mjs.map +1 -1
  31. package/dist/expectation/trivial.cjs +96 -0
  32. package/dist/expectation/trivial.cjs.map +6 -0
  33. package/dist/expectation/trivial.d.ts +13 -0
  34. package/dist/expectation/trivial.mjs +61 -0
  35. package/dist/expectation/trivial.mjs.map +6 -0
  36. package/dist/expectation/types.cjs +9 -12
  37. package/dist/expectation/types.cjs.map +1 -1
  38. package/dist/expectation/types.d.ts +52 -10
  39. package/dist/expectation/types.mjs +8 -10
  40. package/dist/expectation/types.mjs.map +1 -1
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.mjs.map +1 -1
  44. package/package.json +2 -2
  45. package/src/expectation/async.ts +151 -0
  46. package/src/expectation/basic.ts +356 -156
  47. package/src/expectation/diff.ts +8 -9
  48. package/src/expectation/expect.ts +239 -268
  49. package/src/expectation/include.ts +93 -59
  50. package/src/expectation/throwing.ts +102 -41
  51. package/src/expectation/trivial.ts +107 -0
  52. package/src/expectation/types.ts +82 -25
  53. package/src/index.ts +2 -0
  54. package/dist/expectation/void.cjs +0 -111
  55. package/dist/expectation/void.cjs.map +0 -6
  56. package/dist/expectation/void.d.ts +0 -39
  57. package/dist/expectation/void.mjs +0 -77
  58. package/dist/expectation/void.mjs.map +0 -6
  59. package/src/expectation/void.ts +0 -80
@@ -23,122 +23,107 @@ __export(expect_exports, {
23
23
  expect: () => expect
24
24
  });
25
25
  module.exports = __toCommonJS(expect_exports);
26
- var import_types = require("./types.cjs");
26
+ var import_async = require("./async.cjs");
27
27
  var import_basic = require("./basic.cjs");
28
28
  var import_include = require("./include.cjs");
29
29
  var import_throwing = require("./throwing.cjs");
30
- var import_void = require("./void.cjs");
31
- var expectations = {
32
- // basic expectations
33
- toBeA: new import_basic.ToBeA(),
34
- toBeCloseTo: new import_basic.ToBeCloseTo(),
35
- toBeError: new import_basic.ToBeError(),
36
- toBeGreaterThan: new import_basic.ToBeGreaterThan(),
37
- toBeGreaterThanOrEqual: new import_basic.ToBeGreaterThanOrEqual(),
38
- toBeInstanceOf: new import_basic.ToBeInstanceOf(),
39
- toBeLessThan: new import_basic.ToBeLessThan(),
40
- toBeLessThanOrEqual: new import_basic.ToBeLessThanOrEqual(),
41
- toBeWithinRange: new import_basic.ToBeWithinRange(),
42
- toEqual: new import_basic.ToEqual(),
43
- toHaveLength: new import_basic.ToHaveLength(),
44
- toHaveProperty: new import_basic.ToHaveProperty(),
45
- toHaveSize: new import_basic.ToHaveSize(),
46
- toMatch: new import_basic.ToMatch(),
47
- toStrictlyEqual: new import_basic.ToStrictlyEqual(),
30
+ var import_trivial = require("./trivial.cjs");
31
+ var import_types = require("./types.cjs");
32
+ var asyncExpectations = {
33
+ toBeResolved: import_async.toBeResolved,
34
+ toBeRejected: import_async.toBeRejected,
35
+ toBeRejectedWithError: import_async.toBeRejectedWithError
36
+ };
37
+ var syncExpectations = {
38
+ // basic
39
+ toBeA: import_basic.toBeA,
40
+ toBeCloseTo: import_basic.toBeCloseTo,
41
+ toBeError: import_basic.toBeError,
42
+ toBeGreaterThan: import_basic.toBeGreaterThan,
43
+ toBeGreaterThanOrEqual: import_basic.toBeGreaterThanOrEqual,
44
+ toBeInstanceOf: import_basic.toBeInstanceOf,
45
+ toBeLessThan: import_basic.toBeLessThan,
46
+ toBeLessThanOrEqual: import_basic.toBeLessThanOrEqual,
47
+ toBeWithinRange: import_basic.toBeWithinRange,
48
+ toEqual: import_basic.toEqual,
49
+ toHaveLength: import_basic.toHaveLength,
50
+ toHaveProperty: import_basic.toHaveProperty,
51
+ toHaveSize: import_basic.toHaveSize,
52
+ toMatch: import_basic.toMatch,
53
+ toStrictlyEqual: import_basic.toStrictlyEqual,
48
54
  // include
49
- toInclude: new import_include.ToInclude(),
50
- toMatchContents: new import_include.ToMatchContents(),
55
+ toInclude: import_include.toInclude,
56
+ toMatchContents: import_include.toMatchContents,
51
57
  // throwing
52
- toThrow: new import_throwing.ToThrow(),
53
- toThrowError: new import_throwing.ToThrowError(),
54
- // void expectations
55
- toBeDefined: new import_void.ToBeDefined(),
56
- toBeFalse: new import_void.ToBeFalse(),
57
- toBeFalsy: new import_void.ToBeFalsy(),
58
- toBeNaN: new import_void.ToBeNaN(),
59
- toBeNegativeInfinity: new import_void.ToBeNegativeInfinity(),
60
- toBeNull: new import_void.ToBeNull(),
61
- toBePositiveInfinity: new import_void.ToBePositiveInfinity(),
62
- toBeTrue: new import_void.ToBeTrue(),
63
- toBeTruthy: new import_void.ToBeTruthy(),
64
- toBeUndefined: new import_void.ToBeUndefined()
58
+ toThrow: import_throwing.toThrow,
59
+ toThrowError: import_throwing.toThrowError,
60
+ // trivial
61
+ toBeDefined: import_trivial.toBeDefined,
62
+ toBeFalse: import_trivial.toBeFalse,
63
+ toBeFalsy: import_trivial.toBeFalsy,
64
+ toBeNaN: import_trivial.toBeNaN,
65
+ toBeNegativeInfinity: import_trivial.toBeNegativeInfinity,
66
+ toBeNull: import_trivial.toBeNull,
67
+ toBeNullable: import_trivial.toBeNullable,
68
+ toBePositiveInfinity: import_trivial.toBePositiveInfinity,
69
+ toBeTrue: import_trivial.toBeTrue,
70
+ toBeTruthy: import_trivial.toBeTruthy,
71
+ toBeUndefined: import_trivial.toBeUndefined
65
72
  };
66
- var ExpectationsImpl = class {
67
- constructor(value, _positiveExpectations) {
73
+ var allExpectations = {
74
+ ...asyncExpectations,
75
+ ...syncExpectations
76
+ };
77
+ var ExpectationsContextImpl = class {
78
+ constructor(value, negative, expects, negated, parent) {
68
79
  this.value = value;
69
- if (_positiveExpectations) {
70
- this._negative = true;
71
- this._positiveExpectations = _positiveExpectations;
72
- this._negativeExpectations = this;
73
- } else {
74
- this._negative = false;
75
- this._positiveExpectations = this;
76
- this._negativeExpectations = new ExpectationsImpl(value, this);
77
- }
78
- }
79
- _positiveExpectations;
80
- _negativeExpectations;
81
- _negative;
82
- /* == NEW EXPECTATIONS ==================================================== */
83
- forProperty(prop) {
84
- this.toBeDefined();
85
- const child = new ExpectationsImpl(this.value[prop]);
86
- child.parent = { context: this, prop };
87
- return child;
80
+ this.negative = negative;
81
+ this.expects = expects;
82
+ this.negated = negated;
83
+ this.parent = parent;
88
84
  }
89
85
  forValue(value) {
90
86
  return new ExpectationsImpl(value);
91
87
  }
92
- /* == NEGATION ============================================================ */
93
- negated(negative) {
94
- return negative ? this._negativeExpectations : this._positiveExpectations;
95
- }
96
- get not() {
97
- return this._negative ? this._positiveExpectations : this._negativeExpectations;
98
- }
99
- /* == ASYNCHRONOUS EXPECTATIONS =========================================== */
100
- toBeResolved(assert) {
101
- return Promise.resolve().then(() => {
102
- this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
103
- return Promise.allSettled([Promise.resolve(this.value)]);
104
- }).then(([settlement]) => {
105
- if (settlement.status === "fulfilled") {
106
- if (this._negative)
107
- throw new import_types.ExpectationError(this, true, "to be resolved");
108
- if (assert)
109
- assert(new ExpectationsImpl(settlement.value));
110
- } else if (!this._negative) {
111
- throw new import_types.ExpectationError(this, false, "to be resolved");
112
- }
113
- return this._positiveExpectations;
114
- });
115
- }
116
- toBeRejected(assert) {
117
- return Promise.resolve().then(() => {
118
- this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
119
- return Promise.allSettled([Promise.resolve(this.value)]);
120
- }).then(([settlement]) => {
121
- if (settlement.status === "rejected") {
122
- if (this._negative)
123
- throw new import_types.ExpectationError(this, true, "to be rejected");
124
- if (assert)
125
- assert(new ExpectationsImpl(settlement.reason));
126
- } else if (!this._negative) {
127
- throw new import_types.ExpectationError(this, false, "to be rejected");
128
- }
129
- return this._positiveExpectations;
130
- });
88
+ forProperty(prop) {
89
+ this.expects.toBeDefined();
90
+ const value = this.value[prop];
91
+ const parent = { context: this, prop };
92
+ return new ExpectationsImpl(value, parent);
131
93
  }
132
- toBeRejectedWithError(...args) {
133
- return this.toBeRejected((assert) => assert.toBeError(...args));
94
+ };
95
+ var ExpectationsImpl = class {
96
+ _context;
97
+ value;
98
+ not;
99
+ constructor(value, parent, positives) {
100
+ this.value = value;
101
+ if (positives) {
102
+ this.not = positives;
103
+ this._context = new ExpectationsContextImpl(
104
+ value,
105
+ true,
106
+ positives,
107
+ this,
108
+ parent
109
+ );
110
+ } else {
111
+ this._context = new ExpectationsContextImpl(
112
+ value,
113
+ false,
114
+ this,
115
+ this,
116
+ parent
117
+ );
118
+ this.not = new ExpectationsImpl(value, parent, this);
119
+ }
134
120
  }
135
121
  static {
136
- for (const [key, value] of Object.entries(expectations)) {
122
+ for (const [key, value] of Object.entries(allExpectations)) {
137
123
  const expectation = value;
138
124
  const fn = function(...args) {
139
125
  try {
140
- expectation.expect(this._positiveExpectations, this._negative, ...args);
141
- return this._positiveExpectations;
126
+ return expectation.call(this._context, ...args);
142
127
  } catch (error) {
143
128
  if (error instanceof import_types.ExpectationError)
144
129
  Error.captureStackTrace(error, fn);
@@ -150,7 +135,7 @@ var ExpectationsImpl = class {
150
135
  }
151
136
  }
152
137
  };
153
- var ExpectationsMatcherImpl = class {
138
+ var MatcherImpl = class {
154
139
  _matchers;
155
140
  _positiveBuilder;
156
141
  _negativeBuilder;
@@ -164,24 +149,25 @@ var ExpectationsMatcherImpl = class {
164
149
  } else {
165
150
  this._negative = false;
166
151
  this._positiveBuilder = this;
167
- this._negativeBuilder = new ExpectationsMatcherImpl(this._matchers, this);
152
+ this._negativeBuilder = new MatcherImpl(this._matchers, this);
168
153
  }
169
154
  }
170
155
  get not() {
171
156
  return this._negative ? this._positiveBuilder : this._negativeBuilder;
172
157
  }
173
158
  expect(value) {
174
- const expectations2 = new ExpectationsImpl(value);
159
+ const expectations = expect(value);
175
160
  for (const [expectation, negative, args] of this._matchers) {
176
- expectations2.negated(negative)[expectation](...args);
161
+ const expect2 = negative ? expectations.not : expectations;
162
+ expect2[expectation](...args);
177
163
  }
178
164
  }
179
165
  static {
180
166
  Object.defineProperty(this.prototype, import_types.matcherMarker, { value: import_types.matcherMarker });
181
- for (const key in expectations) {
167
+ for (const key in syncExpectations) {
182
168
  Object.defineProperty(this.prototype, key, {
183
169
  value: function(...args) {
184
- return new ExpectationsMatcherImpl([
170
+ return new MatcherImpl([
185
171
  ...this._matchers,
186
172
  [key, this._negative, args]
187
173
  ]);
@@ -194,12 +180,12 @@ var expect = (value) => {
194
180
  return new ExpectationsImpl(value);
195
181
  };
196
182
  Object.defineProperty(expect, "not", {
197
- get: () => new ExpectationsMatcherImpl([]).not
183
+ get: () => new MatcherImpl([]).not
198
184
  });
199
- for (const name in expectations) {
185
+ for (const name in syncExpectations) {
200
186
  Object.defineProperty(expect, name, {
201
187
  value: function(...args) {
202
- const builder = new ExpectationsMatcherImpl([]);
188
+ const builder = new MatcherImpl([]);
203
189
  return builder[name](...args);
204
190
  }
205
191
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/expectation/expect.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgD;AAChD,mBAgBO;AACP,qBAEO;AACP,sBAGO;AACP,kBAWO;AASP,IAAM,eAAe;AAAA;AAAA,EAEnB,OAAO,IAAI,mBAAM;AAAA,EACjB,aAAa,IAAI,yBAAY;AAAA,EAC7B,WAAW,IAAI,uBAAU;AAAA,EACzB,iBAAiB,IAAI,6BAAgB;AAAA,EACrC,wBAAwB,IAAI,oCAAuB;AAAA,EACnD,gBAAgB,IAAI,4BAAe;AAAA,EACnC,cAAc,IAAI,0BAAa;AAAA,EAC/B,qBAAqB,IAAI,iCAAoB;AAAA,EAC7C,iBAAiB,IAAI,6BAAgB;AAAA,EACrC,SAAS,IAAI,qBAAQ;AAAA,EACrB,cAAc,IAAI,0BAAa;AAAA,EAC/B,gBAAgB,IAAI,4BAAe;AAAA,EACnC,YAAY,IAAI,wBAAW;AAAA,EAC3B,SAAS,IAAI,qBAAQ;AAAA,EACrB,iBAAiB,IAAI,6BAAgB;AAAA;AAAA,EAGrC,WAAW,IAAI,yBAAU;AAAA,EACzB,iBAAiB,IAAI,+BAAgB;AAAA;AAAA,EAGrC,SAAS,IAAI,wBAAQ;AAAA,EACrB,cAAc,IAAI,6BAAa;AAAA;AAAA,EAG/B,aAAa,IAAI,wBAAY;AAAA,EAC7B,WAAW,IAAI,sBAAU;AAAA,EACzB,WAAW,IAAI,sBAAU;AAAA,EACzB,SAAS,IAAI,oBAAQ;AAAA,EACrB,sBAAsB,IAAI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;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,IAAI,MAAmB;AACrB,WAAO,KAAK,YAAY,KAAK,mBAAmB,KAAK;AAAA,EACvD;AAAA,EAEA,OAAO,OAAsB;AAC3B,UAAM,eAAe,OAAO,KAAK;AACjC,eAAW,CAAE,aAAa,UAAU,IAAK,KAAK,KAAK,WAAW;AAC5D,YAAMA,UAAS,WAAW,aAAa,MAAa;AACpD,MAAAA,QAAO,WAAW,EAAE,GAAG,IAAI;AAAA,IAC7B;AAAA,EACF;AAAA,EAIA,OAAO;AAEL,WAAO,eAAe,KAAK,WAAW,4BAAe,EAAE,OAAO,2BAAc,CAAC;AAG7E,eAAW,OAAO,kBAAkB;AAClC,aAAO,eAAe,KAAK,WAAW,KAAK;AAAA,QACzC,OAAO,YAA+B,MAAkB;AACtD,iBAAO,IAAI,YAAY;AAAA,YACrB,GAAG,KAAK;AAAA,YAAW,CAAE,KAAK,KAAK,WAAW,IAAK;AAAA,UACjD,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAOO,IAAM,SAAU,CAAc,UAA8B;AACjE,SAAO,IAAI,iBAAiB,KAAK;AACnC;AAGA,OAAO,eAAe,QAAQ,OAAO;AAAA,EACnC,KAAK,MAAM,IAAI,YAAY,CAAC,CAAC,EAAE;AACjC,CAAC;AAGD,WAAW,QAAQ,kBAAkB;AACnC,SAAO,eAAe,QAAQ,MAAM;AAAA,IAClC,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
  }
@@ -1,140 +1,113 @@
1
- import { ToBeA, ToBeCloseTo, ToBeError, ToBeGreaterThan, ToBeGreaterThanOrEqual, ToBeInstanceOf, ToBeLessThan, ToBeLessThanOrEqual, ToBeWithinRange, ToEqual, ToHaveLength, ToHaveProperty, ToHaveSize, ToMatch, ToStrictlyEqual } from './basic';
2
- import { ToInclude, ToMatchContents } from './include';
3
- import { ToThrow, ToThrowError } from './throwing';
4
- import { ToBeDefined, ToBeFalse, ToBeFalsy, ToBeNaN, ToBeNegativeInfinity, ToBeNull, ToBePositiveInfinity, ToBeTrue, ToBeTruthy, ToBeUndefined } from './void';
5
- import type { Constructor, StringMatcher } from './types';
6
- /** Singleton with all imported (known) expectations */
7
- declare const expectations: {
8
- readonly toBeA: ToBeA;
9
- readonly toBeCloseTo: ToBeCloseTo;
10
- readonly toBeError: ToBeError;
11
- readonly toBeGreaterThan: ToBeGreaterThan;
12
- readonly toBeGreaterThanOrEqual: ToBeGreaterThanOrEqual;
13
- readonly toBeInstanceOf: ToBeInstanceOf;
14
- readonly toBeLessThan: ToBeLessThan;
15
- readonly toBeLessThanOrEqual: ToBeLessThanOrEqual;
16
- readonly toBeWithinRange: ToBeWithinRange;
17
- readonly toEqual: ToEqual;
18
- readonly toHaveLength: ToHaveLength;
19
- readonly toHaveProperty: ToHaveProperty;
20
- readonly toHaveSize: ToHaveSize;
21
- readonly toMatch: ToMatch;
22
- readonly toStrictlyEqual: ToStrictlyEqual;
23
- readonly toInclude: ToInclude;
24
- readonly toMatchContents: ToMatchContents;
25
- readonly toThrow: ToThrow;
26
- readonly toThrowError: ToThrowError;
27
- readonly toBeDefined: ToBeDefined;
28
- readonly toBeFalse: ToBeFalse;
29
- readonly toBeFalsy: ToBeFalsy;
30
- readonly toBeNaN: ToBeNaN;
31
- readonly toBeNegativeInfinity: ToBeNegativeInfinity;
32
- readonly toBeNull: ToBeNull;
33
- readonly toBePositiveInfinity: ToBePositiveInfinity;
34
- readonly toBeTrue: ToBeTrue;
35
- readonly toBeTruthy: ToBeTruthy;
36
- readonly toBeUndefined: ToBeUndefined;
1
+ import { toBeRejected, toBeRejectedWithError, toBeResolved } from './async';
2
+ import { toBeA, toBeCloseTo, toBeError, toBeGreaterThan, toBeGreaterThanOrEqual, toBeInstanceOf, toBeLessThan, toBeLessThanOrEqual, toBeWithinRange, toEqual, toHaveLength, toHaveProperty, toHaveSize, toMatch, toStrictlyEqual } from './basic';
3
+ import { toInclude, toMatchContents } from './include';
4
+ import { toThrow, toThrowError } from './throwing';
5
+ import { toBeDefined, toBeFalse, toBeFalsy, toBeNaN, toBeNegativeInfinity, toBeNull, toBeNullable, toBePositiveInfinity, toBeTrue, toBeTruthy, toBeUndefined } from './trivial';
6
+ declare const asyncExpectations: {
7
+ readonly toBeResolved: typeof toBeResolved;
8
+ readonly toBeRejected: typeof toBeRejected;
9
+ readonly toBeRejectedWithError: typeof toBeRejectedWithError;
37
10
  };
38
- /** The type of our imported expectations */
39
- type ExpectationsByName = typeof expectations;
40
- /** Infer expectations parameter from {@link Expectation} type */
41
- type ExpectationParameters<E> = E extends Expectation ? Parameters<E['expect']> extends [any, any, ...infer P] ? P : never : never;
42
- /** Infer return parameter from {@link Expectation} type */
43
- type ExpectationReturn<E, T> = E extends Expectation ? Expectations<T> : never;
44
- /** Infer expectation functions from imported {@link Expectation} instances */
45
- type ImportedExpectations<T = unknown> = {
46
- [k in keyof ExpectationsByName]: (...args: ExpectationParameters<ExpectationsByName[k]>) => ExpectationReturn<ExpectationsByName[k], T>;
11
+ type AsyncExpectations = typeof asyncExpectations;
12
+ declare const syncExpectations: {
13
+ readonly toBeA: typeof toBeA;
14
+ readonly toBeCloseTo: typeof toBeCloseTo;
15
+ readonly toBeError: typeof toBeError;
16
+ readonly toBeGreaterThan: typeof toBeGreaterThan;
17
+ readonly toBeGreaterThanOrEqual: typeof toBeGreaterThanOrEqual;
18
+ readonly toBeInstanceOf: typeof toBeInstanceOf;
19
+ readonly toBeLessThan: typeof toBeLessThan;
20
+ readonly toBeLessThanOrEqual: typeof toBeLessThanOrEqual;
21
+ readonly toBeWithinRange: typeof toBeWithinRange;
22
+ readonly toEqual: typeof toEqual;
23
+ readonly toHaveLength: typeof toHaveLength;
24
+ readonly toHaveProperty: typeof toHaveProperty;
25
+ readonly toHaveSize: typeof toHaveSize;
26
+ readonly toMatch: typeof toMatch;
27
+ readonly toStrictlyEqual: typeof toStrictlyEqual;
28
+ readonly toInclude: typeof toInclude;
29
+ readonly toMatchContents: typeof toMatchContents;
30
+ readonly toThrow: typeof toThrow;
31
+ readonly toThrowError: typeof toThrowError;
32
+ readonly toBeDefined: typeof toBeDefined;
33
+ readonly toBeFalse: typeof toBeFalse;
34
+ readonly toBeFalsy: typeof toBeFalsy;
35
+ readonly toBeNaN: typeof toBeNaN;
36
+ readonly toBeNegativeInfinity: typeof toBeNegativeInfinity;
37
+ readonly toBeNull: typeof toBeNull;
38
+ readonly toBeNullable: typeof toBeNullable;
39
+ readonly toBePositiveInfinity: typeof toBePositiveInfinity;
40
+ readonly toBeTrue: typeof toBeTrue;
41
+ readonly toBeTruthy: typeof toBeTruthy;
42
+ readonly toBeUndefined: typeof toBeUndefined;
47
43
  };
48
- /** An interface describing all expectations returned by `expect(...)` */
49
- export interface Expectations<T = unknown> extends ImportedExpectations<T> {
50
- /**
51
- * The parent of this instance, if and only if this is a child derived from
52
- * a property of the parent instance's value.
53
- */
54
- parent?: ExpectationsParent;
55
- /** The value this {@link Expectations} instance operates on */
56
- value: T;
57
- /** The _negated_ expectations of _this_ {@link Expectations} instance. */
58
- not: Expectations<T>;
59
- /**
60
- * Programmatically return _positive_ or _negative_ {@link Expectations}
61
- * for the value wrapped by this instance.
62
- */
63
- negated(negative: boolean): Expectations<T>;
64
- /** Create an {@link Expectations} associated with a property of this value */
65
- forProperty(prop: string | number | symbol): Expectations;
66
- /** Create a new {@link Expectations} instance for the specified value */
67
- forValue<T = unknown>(value: T): Expectations<T>;
68
- /** Expect the value to be a _resolved_ {@link Promise} */
69
- toBeResolved(): Promise<ExpectationsImpl<T>>;
70
- /**
71
- * Expect the value to be a _resolved_ {@link Promise}, and assert the
72
- * resolved result with the specified callback
73
- */
74
- toBeResolved(assert: (resultExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
75
- /** Expect the value to be a _rejected_ {@link Promise} */
76
- toBeRejected(): Promise<ExpectationsImpl<T>>;
77
- /**
78
- * Expect the value to be a _rejected_ {@link Promise}, and assert the
79
- * rejected reason with the specified callback
80
- */
81
- toBeRejected(assert?: (rejectionExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
82
- /** Expect the value to be a {@link Promise} _rejected_ by an {@link Error} */
83
- toBeRejectedWithError(): Promise<Expectations<T>>;
84
- /**
85
- * Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
86
- * with the specified _message_
87
- */
88
- toBeRejectedWithError(message: StringMatcher): Promise<Expectations<T>>;
89
- /**
90
- * Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
91
- * of the specified _type_
92
- */
93
- toBeRejectedWithError(constructor: Constructor<Error>): Promise<Expectations<T>>;
94
- /**
95
- * Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
96
- * of the specified _type_ and with the specified _message_
97
- */
98
- toBeRejectedWithError(constructor: Constructor<Error>, message: StringMatcher): Promise<Expectations<T>>;
99
- }
100
- /** Parent expectations */
101
- export interface ExpectationsParent {
102
- context: Expectations;
103
- prop: string | number | symbol;
104
- }
105
- /** Basic definition of an {@link Expectation} as an object */
106
- export interface Expectation {
107
- expect(context: Expectations, negative: boolean, ...args: any[]): void;
108
- }
109
- /** Empty interface: the `class` below won't complain about missing stuff */
110
- interface ExpectationsImpl<T = unknown> extends Expectations<T> {
44
+ type SyncExpectations = typeof syncExpectations;
45
+ type AllExpectations = SyncExpectations & AsyncExpectations;
46
+ /** Combine the arguments of a number of overloads (tuples) */
47
+ type OverloadArguments<T> = T extends readonly [infer T, ...infer Rest] ? [
48
+ T,
49
+ ...OverloadArguments<Rest>
50
+ ] : T extends readonly [] ? [] : T extends readonly (infer T)[] ? unknown extends T ? never : T extends undefined ? [] : [
51
+ T
52
+ ] : never;
53
+ /**
54
+ * Remap `Functions` (a record of functions) inferring arguments and forcing
55
+ * return type to `Result`
56
+ */
57
+ type OverloadFunctions<Functions, Result> = {
58
+ [k in keyof Functions]: Functions[k] extends {
59
+ (...args: infer A0): any;
60
+ (...args: infer A1): any;
61
+ (...args: infer A2): any;
62
+ (...args: infer A3): any;
63
+ (...args: infer A4): any;
64
+ (...args: infer A5): any;
65
+ } ? (...args: OverloadArguments<A0 | A1 | A2 | A3 | A4 | A5>) => Result : Functions[k] extends {
66
+ (...args: infer A0): any;
67
+ (...args: infer A1): any;
68
+ (...args: infer A2): any;
69
+ (...args: infer A3): any;
70
+ (...args: infer A4): any;
71
+ } ? (...args: OverloadArguments<A0 | A1 | A2 | A3 | A4>) => Result : Functions[k] extends {
72
+ (...args: infer A0): any;
73
+ (...args: infer A1): any;
74
+ (...args: infer A2): any;
75
+ (...args: infer A3): any;
76
+ } ? (...args: OverloadArguments<A0 | A1 | A2 | A3>) => Result : Functions[k] extends {
77
+ (...args: infer A0): any;
78
+ (...args: infer A1): any;
79
+ (...args: infer A2): any;
80
+ } ? (...args: OverloadArguments<A0 | A1 | A2>) => Result : Functions[k] extends {
81
+ (...args: infer A0): any;
82
+ (...args: infer A1): any;
83
+ } ? (...args: OverloadArguments<A0 | A1>) => Result : Functions[k] extends {
84
+ (...args: infer A0): any;
85
+ } ? (...args: OverloadArguments<A0>) => Result : never;
86
+ };
87
+ /**
88
+ * Expectation functions simply check a _value_, but do not alter the type
89
+ * returned by each expectation.
90
+ */
91
+ export interface ExpectationFunctions<T> extends OverloadFunctions<AsyncExpectations, Promise<Expectations<PromiseLike<T>>>>, OverloadFunctions<SyncExpectations, Expectations<T>> {
111
92
  }
112
- /** Implementation of our {@link Expectations} interface */
113
- declare class ExpectationsImpl<T = unknown> implements Expectations<T> {
93
+ /**
94
+ * An interface describing all expectations returned by `expect(...)`.
95
+ *
96
+ * Each function, upon checking, might return an expectation bound to a
97
+ * different _type_ (for example `.toBeNull()` returns always
98
+ * `Expectations<null>`, inferring that `value` is indeed `null`).
99
+ */
100
+ export interface Expectations<T = unknown> extends AllExpectations {
101
+ /** The value this {@link Expectations} instance operates on */
114
102
  readonly value: T;
115
- private readonly _positiveExpectations;
116
- private readonly _negativeExpectations;
117
- private readonly _negative;
118
- constructor(value: T, _positiveExpectations?: ExpectationsImpl<T>);
119
- forProperty(prop: string | number | symbol): ExpectationsImpl;
120
- forValue<T = unknown>(value: T): ExpectationsImpl<T>;
121
- negated(negative: boolean): ExpectationsImpl<T>;
122
- get not(): ExpectationsImpl<T>;
123
- toBeResolved(assert?: (resultExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
124
- toBeRejected(assert?: (reasonExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
125
- toBeRejectedWithError(...args: [] | [message: StringMatcher] | [constructor: Constructor<Error>] | [constructor: Constructor<Error>, message: StringMatcher]): Promise<ExpectationsImpl<T>>;
103
+ /** The _negated_ expectations of _this_ {@link Expectations} instance. */
104
+ readonly not: ExpectationFunctions<T>;
126
105
  }
127
- /** Infer return parameter from {@link Expectation} type */
128
- type MatcherReturn<E> = E extends Expectation ? ExpectationsMatcher : never;
129
- /** Infer expectation functions from imported {@link Expectation} instances */
130
- type ImportedMatchers = {
131
- [k in keyof ExpectationsByName]: (...args: ExpectationParameters<ExpectationsByName[k]>) => MatcherReturn<ExpectationsByName[k]>;
132
- };
133
106
  /** An interface describing all expectations returned by `expect(...)` */
134
- export interface ExpectationsMatcher extends ImportedMatchers {
135
- not: ExpectationsMatcher;
107
+ export interface Matchers extends OverloadFunctions<SyncExpectations, Matchers> {
108
+ not: Matchers;
136
109
  expect(value: unknown): void;
137
110
  }
138
111
  /** The `expect` function exposing expectations and matchers */
139
- export declare const expect: ExpectationsMatcher & (<T = unknown>(value: T) => Expectations<T>);
112
+ export declare const expect: Matchers & (<T = unknown>(value: T) => Expectations<T>);
140
113
  export {};