deno.land / std@0.224.0 / http / user_agent_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/assert_equals.ts";import { UserAgent } from "./user_agent.ts";
Deno.test({ name: "UserAgent.prototype.browser", async fn(t) { const specs = (await import("./testdata/user_agent/browser-all.json", { with: { type: "json" }, })).default; for (const { desc, ua, expect: { major, name, version } } of specs) { await t.step({ name: desc, fn() { const actual = new UserAgent(ua); assertEquals(actual.browser, { major: major === "undefined" ? undefined : major, name: name === "undefined" ? undefined : name, version: version === "undefined" ? undefined : version, }); }, }); } },});
Deno.test({ name: "UserAgent.prototype.cpu", async fn(t) { const specs = (await import("./testdata/user_agent/cpu-all.json", { with: { type: "json" }, })).default; for (const { desc: name, ua, expect } of specs) { await t.step({ name, fn() { const actual = new UserAgent(ua); assertEquals(actual.cpu, expect); }, }); } },});
Deno.test({ name: "UserAgent.prototype.device", async fn(t) { const specs = (await import("./testdata/user_agent/device-all.json", { with: { type: "json" }, })).default; for (const { desc: name, ua, expect: { vendor, model, type } } of specs) { await t.step({ name, fn() { const actual = new UserAgent(ua); assertEquals(actual.device, { vendor: vendor === "undefined" ? undefined : vendor, model: model === "undefined" ? undefined : model, type: type === "undefined" ? undefined : type, }); }, }); } },});
Deno.test({ name: "UserAgent.prototype.engine", async fn(t) { const specs = (await import("./testdata/user_agent/engine-all.json", { with: { type: "json" }, })).default; for (const { desc, ua, expect: { name, version } } of specs) { await t.step({ name: desc, fn() { const actual = new UserAgent(ua); assertEquals(actual.engine, { name: name === "undefined" ? undefined : name, version: version === "undefined" ? undefined : version, }); }, }); } },});
Deno.test({ name: "UserAgent.prototype.os", async fn(t) { const specs = (await import("./testdata/user_agent/os-all.json", { with: { type: "json" }, })).default; for (const { desc, ua, expect: { name, version } } of specs) { await t.step({ name: desc, fn() { const actual = new UserAgent(ua); assertEquals(actual.os, { name: name === "undefined" ? undefined : name, version: version === "undefined" ? undefined : version, }); }, }); } },});
Version Info