MCPcopy Create free account
hub / github.com/avajs/ava / assertExpectations

Function assertExpectations

lib/assert.js:144–238  ·  view source on GitHub ↗
({actual, expectations, message, prefix, assertion, assertionStack})

Source from the content-addressed store, hash-verified

142// Note: this function *must* throw exceptions, since it can be used
143// as part of a pending assertion for promises.
144function assertExpectations({actual, expectations, message, prefix, assertion, assertionStack}) {
145 const allowThrowAnything = Object.hasOwn(expectations, 'any') && expectations.any;
146 if (!allowThrowAnything && !isNativeError(actual)) {
147 throw new AssertionError(message, {
148 assertion,
149 assertionStack,
150 cause: actual,
151 formattedDetails: [formatWithLabel(`${prefix} exception that is not an error:`, actual)],
152 });
153 }
154
155 if (Object.hasOwn(expectations, 'is') && actual !== expectations.is) {
156 throw new AssertionError(message, {
157 assertion,
158 assertionStack,
159 cause: actual,
160 formattedDetails: [
161 formatWithLabel(`${prefix} unexpected exception:`, actual),
162 formatWithLabel('Expected to be strictly equal to:', expectations.is),
163 ],
164 });
165 }
166
167 if (expectations.instanceOf && !(actual instanceof expectations.instanceOf)) {
168 throw new AssertionError(message, {
169 assertion,
170 assertionStack,
171 cause: actual,
172 formattedDetails: [
173 formatWithLabel(`${prefix} unexpected exception:`, actual),
174 formatWithLabel('Expected instance of:', expectations.instanceOf),
175 ],
176 });
177 }
178
179 if (typeof expectations.name === 'string' && actual.name !== expectations.name) {
180 throw new AssertionError(message, {
181 assertion,
182 assertionStack,
183 cause: actual,
184 formattedDetails: [
185 formatWithLabel(`${prefix} unexpected exception:`, actual),
186 formatWithLabel('Expected name to equal:', expectations.name),
187 ],
188 });
189 }
190
191 if (typeof expectations.message === 'string' && actual.message !== expectations.message) {
192 throw new AssertionError(message, {
193 assertion,
194 assertionStack,
195 cause: actual,
196 formattedDetails: [
197 formatWithLabel(`${prefix} unexpected exception:`, actual),
198 formatWithLabel('Expected message to equal:', expectations.message),
199 ],
200 });
201 }

Callers 2

constructorMethod · 0.85
handlePromiseMethod · 0.85

Calls 2

formatWithLabelFunction · 0.85
matchesFunction · 0.70

Tested by

no test coverage detected