| 103 | }; |
| 104 | |
| 105 | export const expect: Expect = (actual: any, ...rest: Array<any>) => { |
| 106 | if (rest.length > 0) { |
| 107 | throw new Error(class="st">'Expect takes at most one argument.'); |
| 108 | } |
| 109 | |
| 110 | const allMatchers = getMatchers(); |
| 111 | const expectation: any = { |
| 112 | not: {}, |
| 113 | rejects: {not: {}}, |
| 114 | resolves: {not: {}}, |
| 115 | }; |
| 116 | |
| 117 | const err = new JestAssertionError(); |
| 118 | |
| 119 | for (const name of Object.keys(allMatchers)) { |
| 120 | const matcher = allMatchers[name]; |
| 121 | const promiseMatcher = getPromiseMatcher(name, matcher) || matcher; |
| 122 | expectation[name] = makeThrowingMatcher(matcher, false, class="st">'', actual); |
| 123 | expectation.not[name] = makeThrowingMatcher(matcher, true, class="st">'', actual); |
| 124 | |
| 125 | expectation.resolves[name] = makeResolveMatcher( |
| 126 | name, |
| 127 | promiseMatcher, |
| 128 | false, |
| 129 | actual, |
| 130 | err, |
| 131 | ); |
| 132 | expectation.resolves.not[name] = makeResolveMatcher( |
| 133 | name, |
| 134 | promiseMatcher, |
| 135 | true, |
| 136 | actual, |
| 137 | err, |
| 138 | ); |
| 139 | |
| 140 | expectation.rejects[name] = makeRejectMatcher( |
| 141 | name, |
| 142 | promiseMatcher, |
| 143 | false, |
| 144 | actual, |
| 145 | err, |
| 146 | ); |
| 147 | expectation.rejects.not[name] = makeRejectMatcher( |
| 148 | name, |
| 149 | promiseMatcher, |
| 150 | true, |
| 151 | actual, |
| 152 | err, |
| 153 | ); |
| 154 | } |
| 155 | |
| 156 | return expectation; |
| 157 | }; |
| 158 | |
| 159 | const getMessage = (message?: () => string) => |
| 160 | (message && message()) || |