| 44 | } |
| 45 | |
| 46 | export class ChainableAssertions implements AssertionRecord { |
| 47 | private ctx: AssertionContext |
| 48 | |
| 49 | constructor(ctx: AssertionContext) { |
| 50 | this.ctx = ctx |
| 51 | } |
| 52 | |
| 53 | private get unversionedActual(): unknown { |
| 54 | if (this.versionableActual instanceof TypeAssertionMapping) { |
| 55 | return this.versionableActual.fn( |
| 56 | this.ctx.typeRelationshipAssertionEntries![0][1], |
| 57 | this.ctx |
| 58 | )!.actual |
| 59 | } |
| 60 | return this.versionableActual |
| 61 | } |
| 62 | |
| 63 | private get versionableActual(): VersionableActual { |
| 64 | return this.ctx.versionableActual |
| 65 | } |
| 66 | |
| 67 | private get serializedActual(): unknown { |
| 68 | return snapshot(this.unversionedActual) |
| 69 | } |
| 70 | |
| 71 | unwrap(opts?: UnwrapOptions): unknown { |
| 72 | const value = |
| 73 | opts?.versionable ? this.versionableActual : this.unversionedActual |
| 74 | return opts?.serialize ? snapshot(value) : value |
| 75 | } |
| 76 | |
| 77 | private snapRequiresUpdate(expectedSerialized: unknown) { |
| 78 | return ( |
| 79 | !isDeepStrictEqual(this.serializedActual, expectedSerialized) || |
| 80 | // If actual is undefined, we still need to write the "undefined" literal |
| 81 | // to the snap even though it will serialize to the same value as the (nonexistent) first arg |
| 82 | this.unversionedActual === undefined |
| 83 | ) |
| 84 | } |
| 85 | |
| 86 | get unknown(): this { |
| 87 | return this |
| 88 | } |
| 89 | |
| 90 | is(expected: unknown): this { |
| 91 | assert.equal(this.unversionedActual, expected) |
| 92 | return this |
| 93 | } |
| 94 | |
| 95 | equals(expected: unknown): this { |
| 96 | assertEquals(expected, this.versionableActual, this.ctx) |
| 97 | return this |
| 98 | } |
| 99 | |
| 100 | satisfies(def: unknown): this { |
| 101 | assertSatisfies(type.raw(def), this.versionableActual, this.ctx) |
| 102 | return this |
| 103 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…