Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shontzu-deriv committed May 15, 2024
1 parent 46c28a6 commit 7430198
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"vite": "^5.1.2",
"vite-plugin-dts": "^3.7.2",
"vitest": "^1.2.2"
},
"dependencies": {
"ua-parser-js": "^1.0.37"
}
}
44 changes: 44 additions & 0 deletions src/utils/__test__/mobileOSDetectAsync.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { mobileOSDetectAsync, getOSNameWithUAParser } from "../mobileOSDetectAsync.utils";
import UAParser from "ua-parser-js";

describe("mobileOSDetectAsync", () => {

Check failure on line 4 in src/utils/__test__/mobileOSDetectAsync.utils.spec.ts

View workflow job for this annotation

GitHub Actions / test

src/utils/__test__/mobileOSDetectAsync.utils.spec.ts

ReferenceError: describe is not defined ❯ src/utils/__test__/mobileOSDetectAsync.utils.spec.ts:4:1
test('should return "Windows Phone" for Windows Phone user agent', async () => {
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("windows phone");
expect(await mobileOSDetectAsync()).toBe("Windows Phone");
});

test('should return "Android" for Android user agent', async () => {
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("android");
expect(await mobileOSDetectAsync()).toBe("Android");
});

test('should return "iOS" for iOS user agent', async () => {
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("iPhone");
jest.spyOn(window, "MSStream", "get").mockReturnValue({
msClose: () => {},
msDetachStream: () => {},
type: "someType",
});
expect(await mobileOSDetectAsync()).toBe("iOS");
});

test('should return "iOS" for iOS user agent', async () => {
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("iPhone");
jest.spyOn(window, "MSStream", "get").mockReturnValue({
msClose: () => {},
msDetachStream: () => {},
type: "someType",
});
expect(await mobileOSDetectAsync()).toBe("iOS");
});

test('should return "unknown" for unknown user agent', async () => {
jest.spyOn(window.navigator, "userAgent", "get").mockReturnValue("unknown");
expect(await mobileOSDetectAsync()).toBe("unknown");
});

test("should return the OS name", () => {
jest.spyOn(UAParser, "OS", "get").mockReturnValue({ NAME: "name", VERSION: "version" });
expect(getOSNameWithUAParser()).toBe("name");
});
});

0 comments on commit 7430198

Please sign in to comment.