@rcompat/test 0.8.0 → 0.8.2

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/README.md CHANGED
@@ -223,9 +223,11 @@ The assert function passed to test cases.
223
223
  | `false()` | Assert value is `false` |
224
224
  | `null()` | Assert value is `null` |
225
225
  | `undefined()` | Assert value is `undefined` |
226
+ | `defined()` | Assert value is not `undefined` |
226
227
  | `instance(constructor)` | Assert value is instance of class |
227
228
  | `throws(message?)` | Assert function throws (optional message) |
228
229
  | `tries()` | Assert function does not throw |
230
+ | `not` | Negate the next asertion |
229
231
  | `type<T>()` | Compile-time type assertion |
230
232
  | `nottype<T>()` | Compile-time negative type assertion |
231
233
  | `pass()` | Manually pass the assertion |
@@ -4,6 +4,7 @@ type Equals<X, Y> = (<T>() => T extends X ? true : false) extends <T>() => T ext
4
4
  export default class Assert<const Actual> {
5
5
  #private;
6
6
  constructor(test: Test, actual?: Actual);
7
+ get not(): this;
7
8
  equals(expected: unknown): this;
8
9
  nequals(expected: unknown): this;
9
10
  type<const Expected extends Equals<Actual, Expected> extends true ? unknown : Print<Actual>>(_expected?: Expected): this;
@@ -12,6 +13,7 @@ export default class Assert<const Actual> {
12
13
  false(): this;
13
14
  null(): this;
14
15
  undefined(): this;
16
+ defined(): this;
15
17
  instance(expected: UnknownFunction): this;
16
18
  throws(expected?: string): this;
17
19
  tries(): this;
@@ -3,12 +3,18 @@ import equals from "#equals";
3
3
  export default class Assert {
4
4
  #test;
5
5
  #actual;
6
+ #negate = false;
6
7
  constructor(test, actual) {
7
8
  this.#actual = actual;
8
9
  this.#test = test;
9
10
  }
10
11
  #report(passed, expected, actual) {
11
- this.#test.report(actual ?? this.#actual, expected, passed);
12
+ const negate = this.#negate;
13
+ // reset negation
14
+ this.#negate = false;
15
+ const final_passed = negate ? !passed : passed;
16
+ const final_expected = negate ? { not: expected } : expected;
17
+ this.#test.report(actual ?? this.#actual, final_expected, final_passed);
12
18
  }
13
19
  #passed() {
14
20
  this.#report(true, undefined);
@@ -16,6 +22,10 @@ export default class Assert {
16
22
  #failed(expected, actual) {
17
23
  this.#report(false, expected, actual);
18
24
  }
25
+ get not() {
26
+ this.#negate = !this.#negate;
27
+ return this;
28
+ }
19
29
  equals(expected) {
20
30
  this.#report(equals(this.#actual, expected), expected);
21
31
  return this;
@@ -47,6 +57,9 @@ export default class Assert {
47
57
  undefined() {
48
58
  return this.#static(undefined);
49
59
  }
60
+ defined() {
61
+ return this.not.undefined();
62
+ }
50
63
  instance(expected) {
51
64
  this.#report(this.#actual instanceof expected, expected);
52
65
  return this;
@@ -1,2 +1,3 @@
1
1
  export { default } from "#index";
2
+ export type { default as Asserter } from "#Asserter";
2
3
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rcompat/test",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Standard library testing",
5
5
  "bugs": "https://github.com/rcompat/rcompat/issues",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "directory": "packages/test"
16
16
  },
17
17
  "devDependencies": {
18
- "@rcompat/fs": "^0.25.0",
18
+ "@rcompat/fs": "^0.25.2",
19
19
  "@rcompat/type": "^0.9.0"
20
20
  },
21
21
  "type": "module",