Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more
Module

x/fresh/tests/deps.ts>Page#emulateMediaFeatures

The next-gen web framework.
Extremely Popular
Go to Latest
method Page.prototype.emulateMediaFeatures
Re-export
import { Page } from "https://deno.land/x/fresh@1.5.4/tests/deps.ts";

Examples

Example 1

await page.emulateMediaFeatures([
  {name: 'prefers-color-scheme', value: 'dark'},
]);
await page.evaluate(
  () => matchMedia('(prefers-color-scheme: dark)').matches
);
// β†’ true
await page.evaluate(
  () => matchMedia('(prefers-color-scheme: light)').matches
);
// β†’ false

await page.emulateMediaFeatures([
  {name: 'prefers-reduced-motion', value: 'reduce'},
]);
await page.evaluate(
  () => matchMedia('(prefers-reduced-motion: reduce)').matches
);
// β†’ true
await page.evaluate(
  () => matchMedia('(prefers-reduced-motion: no-preference)').matches
);
// β†’ false

await page.emulateMediaFeatures([
  {name: 'prefers-color-scheme', value: 'dark'},
  {name: 'prefers-reduced-motion', value: 'reduce'},
]);
await page.evaluate(
  () => matchMedia('(prefers-color-scheme: dark)').matches
);
// β†’ true
await page.evaluate(
  () => matchMedia('(prefers-color-scheme: light)').matches
);
// β†’ false
await page.evaluate(
  () => matchMedia('(prefers-reduced-motion: reduce)').matches
);
// β†’ true
await page.evaluate(
  () => matchMedia('(prefers-reduced-motion: no-preference)').matches
);
// β†’ false

await page.emulateMediaFeatures([{name: 'color-gamut', value: 'p3'}]);
await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches);
// β†’ true
await page.evaluate(() => matchMedia('(color-gamut: p3)').matches);
// β†’ true
await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches);
// β†’ false

Parameters

optional
features: MediaFeature[]
  • <?Array<Object>> Given an array of media feature objects, emulates CSS media features on the page. Each media feature object must have the following properties:

Returns

Promise<void>