(chai, utils)
| 76 | } |
| 77 | |
| 78 | export const SnapshotPlugin: ChaiPlugin = (chai, utils) => { |
| 79 | for (const key of ['matchSnapshot', 'toMatchSnapshot']) { |
| 80 | utils.addMethod( |
| 81 | chai.Assertion.prototype, |
| 82 | key, |
| 83 | wrapAssertion(utils, key, function ( |
| 84 | this, |
| 85 | propertiesOrHint?: object | string, |
| 86 | hint?: string, |
| 87 | ) { |
| 88 | const result = toMatchSnapshotImpl({ |
| 89 | assertion: this, |
| 90 | received: utils.flag(this, 'object'), |
| 91 | ...normalizeArguments(propertiesOrHint, hint), |
| 92 | }) |
| 93 | return assertMatchResult(result, chai.util.flag(this, 'message')) |
| 94 | }), |
| 95 | ) |
| 96 | } |
| 97 | |
| 98 | utils.addMethod( |
| 99 | chai.Assertion.prototype, |
| 100 | 'toMatchFileSnapshot', |
| 101 | function (this: Chai.Assertion, filepath: string, hint?: string) { |
| 102 | // set name manually since it's not wrapped by wrapAssertion |
| 103 | utils.flag(this, '_name', 'toMatchFileSnapshot') |
| 104 | // validate early synchronously just not to break some existing tests |
| 105 | validateAssertion(this) |
| 106 | const resultPromise = toMatchFileSnapshotImpl({ |
| 107 | assertion: this, |
| 108 | received: utils.flag(this, 'object'), |
| 109 | filepath, |
| 110 | hint, |
| 111 | }) |
| 112 | const assertPromise = resultPromise.then(result => |
| 113 | assertMatchResult(result, chai.util.flag(this, 'message')), |
| 114 | ) |
| 115 | return recordAsyncExpect( |
| 116 | getTest(this), |
| 117 | assertPromise, |
| 118 | createAssertionMessage(utils, this, true), |
| 119 | new Error('resolves'), |
| 120 | utils.flag(this, 'soft'), |
| 121 | ) |
| 122 | }, |
| 123 | ) |
| 124 | |
| 125 | utils.addMethod( |
| 126 | chai.Assertion.prototype, |
| 127 | 'toMatchInlineSnapshot', |
| 128 | wrapAssertion(utils, 'toMatchInlineSnapshot', function __INLINE_SNAPSHOT_OFFSET_3__( |
| 129 | this, |
| 130 | propertiesOrInlineSnapshot?: object | string, |
| 131 | inlineSnapshotOrHint?: string, |
| 132 | hint?: string, |
| 133 | ) { |
| 134 | const result = toMatchSnapshotImpl({ |
| 135 | assertion: this, |
nothing calls this directly
no test coverage detected