---
title: "@std/testing"
description: "Tools for testing Deno code like snapshot testing, bdd testing, and time mocking"
jsr: jsr:@std/testing
pkg: testing
version: 1.0.17
generated: true
stability: stable
---
<!-- Autogenerated from JSR docs. Do not edit directly. -->

## Overview

<p>This package provides utilities for testing.</p>
<ul>
<li><a href="https://jsr.io/@std/testing/doc/bdd/~" rel="nofollow">BDD style testing</a></li>
<li><a href="https://jsr.io/@std/testing/doc/mock/~" rel="nofollow">Test doubles (mocking)</a></li>
<li><a href="https://jsr.io/@std/testing/doc/time/~" rel="nofollow">Faking time and timers</a></li>
<li><a href="https://jsr.io/@std/testing/doc/snapshot/~" rel="nofollow">Snapshot testing</a></li>
<li><a href="https://jsr.io/@std/testing/doc/types/~" rel="nofollow">Type assertions</a></li>
</ul>

```js
import { assertSpyCalls, spy } from "@std/testing/mock";
import { FakeTime } from "@std/testing/time";

function secondInterval(cb: () => void): number {
  return setInterval(cb, 1000);
}

Deno.test("secondInterval calls callback every second and stops after being cleared", () => {
  using time = new FakeTime();

  const cb = spy();
  const intervalId = secondInterval(cb);
  assertSpyCalls(cb, 0);
  time.tick(500);
  assertSpyCalls(cb, 0);
  time.tick(500);
  assertSpyCalls(cb, 1);
  time.tick(3500);
  assertSpyCalls(cb, 4);

  clearInterval(intervalId);
  time.tick(1000);
  assertSpyCalls(cb, 4);
});
```

### Add to your project

```sh
deno add jsr:@std/testing
```

<a href="https://jsr.io/@std/testing/doc" class="docs-cta jsr-cta">See all symbols in @std/testing on
<svg class="inline ml-1" viewBox="0 0 13 7" aria-hidden="true" height="20"><path d="M0,2h2v-2h7v1h4v4h-2v2h-7v-1h-4" fill="#083344"></path><g fill="#f7df1e"><path d="M1,3h1v1h1v-3h1v4h-3"></path><path d="M5,1h3v1h-2v1h2v3h-3v-1h2v-1h-2"></path><path d="M9,2h3v2h-1v-1h-1v3h-1"></path></g></svg></a>

<!-- custom:start -->
<!-- Add persistent custom content below. This section is preserved across generations. -->

<!-- custom:end -->
