deno.land / std@0.139.0 / testing / sinon_example.ts

sinon_example.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license./** * Run this example with: * * deno test ./testing/sinon_example.ts */import sinon from "https://cdn.skypack.dev/sinon@11.1.2?dts";import chai from "https://cdn.skypack.dev/chai@4.3.4?dts";
Deno.test("stubbed callback", () => { const callback = sinon.stub(); callback.withArgs(42).returns(1); callback.withArgs(1).throws(new Error("test-error"));
chai.assert.isUndefined(callback()); // No return value, no exception chai.assert.equal(callback(42), 1); // Returns 1 chai.assert.equal(callback.withArgs(42).callCount, 1); // Use withArgs in assertion chai.assert.throws(() => { callback(1); }, "test-error"); // Throws Error("test-error")});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2121

Version Info

Tagged at
a week ago