Performance: Assertions and matchers
Assertions and matchers affect test execution speed and resource use during development but do not impact production page load or rendering.
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; Deno.test("fast test", () => { assertEquals(1 + 1, 2); });
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; Deno.test("slow test", () => { for (let i = 0; i < 1000000; i++) { assertEquals(i, i); } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy assertions in loops | 0 | 0 | 0 | [X] Bad |
| Simple direct assertions | 0 | 0 | 0 | [OK] Good |
assertEquals to check equality.assertEquals(actual, expected), matching assertEquals(actual, expected); exactly.import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const result = 5 + 3;
assertEquals(result, 8);result is assigned 5 + 3, which equals 8.result (8) with expected value 8, so it matches and passes.import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const value = "hello";
assertEquals(value, Hello);Hello without quotes, so JavaScript treats it as a variable.Hello is not defined, this causes a ReferenceError at runtime.result.includes(10) which returns true if 10 is in the array, then asserts it equals true. This is correct.contains which is not a valid JavaScript method.Pass the test and this pattern moves unknown