Home / Function/ expectUrlPrefetched() — astro Function Reference

expectUrlPrefetched() — astro Function Reference

Architecture documentation for the expectUrlPrefetched() function in prefetch.test.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  61c8dac1_d93d_3462_cbef_1f0d41e1698e["expectUrlPrefetched()"]
  1c683310_85be_7904_6ff5_67c2a35b7c0b["prefetch.test.js"]
  61c8dac1_d93d_3462_cbef_1f0d41e1698e -->|defined in| 1c683310_85be_7904_6ff5_67c2a35b7c0b
  style 61c8dac1_d93d_3462_cbef_1f0d41e1698e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/e2e/prefetch.test.js lines 27–47

async function expectUrlPrefetched(url, page, count) {
	try {
		await expect(page.locator(`link[rel="prefetch"][href$="${url}"]`)).toBeAttached();
	} catch {
		// If link is not found, check if it was fetched via `fetch()`
		expect(reqUrls, `${url} is not prefetched via link or fetch`).toContainEqual(url);
	}

	if (count != null) {
		const linkCount = await page.locator(`link[rel="prefetch"][href$="${url}"]`).count();
		try {
			expect(linkCount).toBe(count);
		} catch {
			const fetchCount = reqUrls.filter((u) => u.includes(url)).length;
			expect(
				fetchCount,
				`${url} should be prefetched ${count} time(s), but is prefetch with link ${linkCount} time(s) and with fetch ${fetchCount} time(s)`,
			).toEqual(count);
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does expectUrlPrefetched() do?
expectUrlPrefetched() is a function in the astro codebase, defined in packages/astro/e2e/prefetch.test.js.
Where is expectUrlPrefetched() defined?
expectUrlPrefetched() is defined in packages/astro/e2e/prefetch.test.js at line 27.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free