deno.land / std@0.224.0 / expect / _to_have_returned_with.ts

_to_have_returned_with.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { MatcherContext, MatchResult } from "./_types.ts";import { AssertionError } from "../assert/assertion_error.ts";import { equal } from "../assert/equal.ts";import { getMockCalls } from "./_mock_util.ts";import { inspectArg } from "./_inspect_args.ts";
export function toHaveReturnedWith( context: MatcherContext, expected: unknown,): MatchResult { const calls = getMockCalls(context.value); const returned = calls.filter((call) => call.returns); const returnedWithExpected = returned.some((call) => equal(call.returned, expected) );
if (context.isNot) { if (returnedWithExpected) { throw new AssertionError( `Expected the mock function to not have returned with ${ inspectArg(expected) }, but it did`, ); } } else { if (!returnedWithExpected) { throw new AssertionError( `Expected the mock function to have returned with ${ inspectArg(expected) }, but it did not`, ); } }}
std

Version Info

Tagged at
3 weeks ago