jest-useragent-mock
v0.1.1
Published
Mock `navigator.userAgent` when run unit test cases with jest.
Downloads
98,850
Readme
jest-useragent-mock
Mock
navigator.userAgent
when run unit test cases with jest.
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
- Add some common useragents, such as WeChat, etc.