# jest-useragent-mock

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

Latest version **0.1.1** (published 2020-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-useragent-mock
pnpm add jest-useragent-mock
yarn add jest-useragent-mock
bun add jest-useragent-mock
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-03-13 |
| First published | 2019-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 85 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | ariesjia |
| Maintainers | ariesjia |
| Keywords | mock, jest, useragent |

## Links

- npm: https://www.npmjs.com/package/jest-useragent-mock
- Repository: https://github.com/ariesjia/jest-useragent-mock
- Homepage: https://github.com/ariesjia/jest-useragent-mock#readme
- Issues: https://github.com/ariesjia/jest-useragent-mock/issues
- npm.io page: https://npm.io/package/jest-useragent-mock

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@crvouga/mockingbird-service-junction](https://npm.io/package/@crvouga/mockingbird-service-junction.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-medplum](https://npm.io/package/@crvouga/mockingbird-service-medplum.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-genebygene](https://npm.io/package/@crvouga/mockingbird-service-genebygene.md) — 0 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-03-13
- 0.1.0 — 2020-03-13
- 0.0.3 — 2019-01-31
- 0.0.2 — 2019-01-30

## README

# jest-useragent-mock
> Mock `navigator.userAgent` when run unit test cases with jest.

[![Build Status](https://travis-ci.org/ariesjia/jest-useragent-mock.svg?branch=master)](https://travis-ci.org/ariesjia/jest-useragent-mock)
[![license](https://badgen.net/badge/license/MIT/blue)](https://github.com/ariesjia/jest-useragent-mock/blob/master/LICENSE)
[![coverage](https://badgen.net/codecov/c/github/ariesjia/jest-useragent-mock)](https://codecov.io/gh/ariesjia/jest-useragent-mock)


## Install
```bash
// use yarn
yarn add jest-useragent-mock -D
// use npm
npm install jest-useragent-mock  --save-dev
```

## Setup
`jest.config.js`
```javascript
{
   "setupFiles": ["jest-useragent-mock"]
}
```

## Usage
```javascript
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.

---
_Source: https://npm.io/package/jest-useragent-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
