deno.land / std@0.166.0 / testing / mock_examples / random_test.ts

random_test.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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { assertSpyCall, assertSpyCalls, returnsNext, stub } from "../mock.ts";import { assertEquals } from "../asserts.ts";import { _internals, randomMultiple } from "./random.ts";
Deno.test("randomMultiple uses randomInt to generate random multiples between -10 and 10 times the value", () => { const randomIntStub = stub(_internals, "randomInt", returnsNext([-3, 3]));
try { assertEquals(randomMultiple(5), -15); assertEquals(randomMultiple(5), 15); } finally { // unwraps the randomInt method on the _internals object randomIntStub.restore(); }
// asserts that randomIntStub was called at least once and details about the first call. assertSpyCall(randomIntStub, 0, { args: [-10, 10], returned: -3, }); // asserts that randomIntStub was called at least twice and details about the second call. assertSpyCall(randomIntStub, 1, { args: [-10, 10], returned: 3, });
// asserts that randomIntStub was only called twice. assertSpyCalls(randomIntStub, 2);});
std

Version Info

Tagged at
a year ago