tea-jest-useragent-mock
v0.1.4
Published
Mock `navigator.userAgent` when run unit test cases with jest.
Downloads
4
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 useragent', () => {
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.