browser.test.ts 868 B

12345678910111213141516171819202122232425262728
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { isFirefox } from '..'
  3. describe('browser', () => {
  4. it('isFirefox should work', () => {
  5. const userAgents = [
  6. [
  7. 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0',
  8. true,
  9. ],
  10. ['Mozilla/5.0 (Android; Mobile; rv:40.0) Gecko/40.0 Firefox/40.0', true],
  11. [
  12. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0',
  13. true,
  14. ],
  15. [
  16. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36',
  17. false,
  18. ],
  19. ] as const
  20. for (const [userAgent, value] of userAgents) {
  21. vi.spyOn(navigator, 'userAgent', 'get').mockImplementation(
  22. () => userAgent
  23. )
  24. expect(isFirefox()).toBe(value)
  25. }
  26. })
  27. })