0Pricing
Edge Computing with Cloudflare Workers & Deno · Lezione

Testare le applicazioni Deno

Scrivete ed eseguite test per app Deno usando il test runner integrato, le asserzioni e il mocking, per ottenere codice edge affidabile.

Testare le applicazioni Deno è una lezione Edge Computing with Cloudflare Workers & Deno gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Edge Computing with Cloudflare Workers & Deno, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Edge Computing with Cloudflare Workers & Deno include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Built-in Testing

Deno ships with a built-in test runner — no extra framework or config needed. Just write tests and run deno test.

Your First Test

Register a test with Deno.test. It takes a name and a function.

Deno.test('adds numbers', () => {
  const sum = 2 + 3;
  if (sum !== 5) throw new Error('wrong');
});

The Assertions Module

Use the standard library's assertions for clearer failures instead of manual throws.

import { assertEquals } from 'jsr:@std/assert';

Deno.test('math', () => {
  assertEquals(2 + 3, 5);
});

Running Tests

Run all tests in your project. Deno discovers files ending in _test.ts or .test.ts automatically.

deno test
deno test --allow-net

Async Tests

Tests can be async — just return a promise or mark the function async. Deno awaits it before reporting.

Deno.test('fetches data', async () => {
  const res = await fetch('https://example.com');
  assertEquals(res.status, 200);
});

Test Steps

Break a complex test into named steps with t.step for clearer output and partial results.

Deno.test('user flow', async (t) => {
  await t.step('signup', () => {});
  await t.step('login', () => {});
});

Permissions in Tests

Tests obey Deno's permission model. A test needing network access fails without --allow-net, so you test real security boundaries.

Mocking & Spies

The std testing module provides spies, stubs, and mocks to isolate units from external services.

import { spy } from 'jsr:@std/testing/mock';
const log = spy(console, 'log');

Snapshot Testing

Deno's assertSnapshot stores expected output and compares future runs against it — great for stable structured responses.

Coverage Reports

Measure how much code your tests exercise with the built-in coverage tools.

deno test --coverage=cov
deno coverage cov

Testing Edge Logic

Structure handlers as pure functions of a Request so you can test them without a running server — ideal for edge code.

export function handler(req: Request) {
  return new Response('ok');
}

Quick Check

Test your Deno testing knowledge.

Recap

You learned to write tests with Deno.test, use std assertions, handle async and steps, respect permissions, mock dependencies, and measure coverage — keeping your edge code reliable.

Domande Frequenti

La lezione «Testare le applicazioni Deno» è gratuita?

Sì — il testo completo di «Testare le applicazioni Deno» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Edge Computing with Cloudflare Workers & Deno, passa a CoddyKit PRO. Il corso Edge Computing with Cloudflare Workers & Deno include 4 lezioni in totale.

Cosa imparerò in «Testare le applicazioni Deno»?

Scrivete ed eseguite test per app Deno usando il test runner integrato, le asserzioni e il mocking, per ottenere codice edge affidabile. Eserciti Edge Computing with Cloudflare Workers & Deno con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Edge Computing with Cloudflare Workers & Deno?

Non è richiesta alcuna esperienza precedente. Edge Computing with Cloudflare Workers & Deno su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Testare le applicazioni Deno»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Edge Computing with Cloudflare Workers & Deno?

Sì. Ogni lezione Edge Computing with Cloudflare Workers & Deno include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Elementi essenziali del runtime Deno
  2. Sistema di moduli e autorizzazioni
  3. Sviluppare app Deno locali
  4. Testare le applicazioni Deno
← Torna a Edge Computing with Cloudflare Workers & Deno