On this page
Setup and teardown APIs
To make testing easier, you can use these APIs to help perform setup and teardown for test cases:
Deno.test.beforeAllDeno.test.beforeEachDeno.test.afterAllDeno.test.afterEach
Here’s a concrete example showing how to set up a test database:
;
;
let testDb: sqlite.;
// Run once before all tests
Deno.. testDb = ;
testDb. id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE
);
`);
});
// Run before each individual test
Deno.. testDb.;
const insert = testDb. "INSERT INTO users (name, email) VALUES (?, ?)",
);
insert.;
insert.;
});
// Run after each individual test
Deno.. // Clean up test data
testDb.;
});
// Run once after all tests
Deno.. testDb.;
});
Deno. const query = testDb.;
const user = query.;
;
});
Deno. const insert = testDb. "INSERT INTO users (name, email) VALUES (?, ?)",
);
insert.;
const countQuery = testDb.;
const result = countQuery.;
; // 2 from beforeEach + 1 new
});