deno.land / std@0.224.0 / expect / _to_have_returned_with.ts
12345678910111213141516171819202122232425262728293031323334353637// 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`, ); } }}
Version Info