Miss any of our Open RFC calls?Watch the recordings here! »

jest-useragent-mock

0.1.1 • Public • Published

jest-useragent-mock

Mock navigator.userAgent when run unit test cases with jest.

Build Status license coverage

Install

// use yarn
yarn add jest-useragent-mock -D
// use npm
npm install jest-useragent-mock  --save-dev

Setup

jest.config.js

{
   "setupFiles": ["jest-useragent-mock"]
}

Usage

import { clear, mockUserAgent } from 'jest-useragent-mock'
 
describe('test usergaent', () => {
  afterEach(() => {
    clear()
  })
 
  it('can mock userAgent', () => {
    const mockAgent = 'test'
    mockUserAgent(mockAgent)
    expect(window.navigator.userAgent).toEqual(mockAgent)
  })
})
 

TODO

  1. Add some common useragents, such as WeChat, etc.

Install

npm i jest-useragent-mock

DownloadsWeekly Downloads

15,043

Version

0.1.1

License

MIT

Unpacked Size

87 kB

Total Files

26

Last publish

Collaborators

  • avatar