2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DenoからSinon.jsを使う

Last updated at Posted at 2020-04-04

概要

  • DenoからSinon.jsを使用する方法について記載します。
  • Sinon.jsはモックやスタブ等を提供するJavaScriptライブラリです。

使い方

import sinon from 'https://cdn.pika.dev/sinon@^8.1.1'; // (1)

const spy = sinon.spy();
spy();
spy();
sinon.assert.calledTwice(spy);

(1)の部分で、Pika CDNからSinon.jsを読み込んでいます。

Pika CDNはDenoをサポートしており、import対象のモジュールに対応する型定義ファイルが存在すれば、X-TypeScript-Typesヘッダにその型定義ファイルのURLを設定した状態でHTTPレスポンスを返却してくれます。

DenoはX-TypeScript-Typesヘッダに設定されたURLからTypeScriptの型定義ファイルをダウンロードし、型チェックを行います。

vscode-deno等のDenoをサポートしたエディタ・IDEを利用していれば、入力補完や型チェック等もちゃんと機能します。

screenshot.png

後は、Node.jsから使用する時と同様にSinon.jsを使用することができます。

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?