Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jorisre/jest-wake-lock-mock
Mock Screen Wake Lock API `navigator.wakeLock` with ease and run your tests using Jest
https://github.com/jorisre/jest-wake-lock-mock
jest mock nosleep test wakelock
Last synced: 20 days ago
JSON representation
Mock Screen Wake Lock API `navigator.wakeLock` with ease and run your tests using Jest
- Host: GitHub
- URL: https://github.com/jorisre/jest-wake-lock-mock
- Owner: jorisre
- License: mit
- Created: 2020-10-31T21:19:12.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-01T21:04:29.000Z (almost 4 years ago)
- Last Synced: 2024-10-17T21:44:51.697Z (22 days ago)
- Topics: jest, mock, nosleep, test, wakelock
- Language: TypeScript
- Homepage: https://npm.im/jest-wake-lock-mock
- Size: 357 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-jest - jest-wake-lock-mock
README
Welcome to jest-wake-lock-mock 👋
> Mock [Screen Wake Lock API](https://w3c.github.io/screen-wake-lock/) _(`navigator.wakeLock`)_ with ease and run your tests using Jest
### 🏠 [Homepage](https://github.com/jorisre/jest-wake-lock-mock#readme)
## Prerequisites
- node >=10
## Install
```sh
npm i -D jest-wake-lock-mock
# or
yarn add -D jest-wake-lock-mock
```## Usage
In your `jest.config.js` or `package.json` under `jest` section create a [`setupFiles`](https://jestjs.io/docs/en/configuration#setupfiles-array) array and add `jest-wake-lock-mock` to it.
```js
{
setupFiles: ['jest-wake-lock-mock'],
// jest config...
}
```## Tests
Write your tests with confidence using the same [Screen Wake Lock API](https://w3c.github.io/screen-wake-lock/) api as in the browser.
**Example** ([More](https://github.com/jorisre/jest-wake-lock-mock/blob/master/test/jest-wake-lock-mock.test.ts)):
```js
const requestWakeLock = async () => {
try {
const wakeLock = await navigator.wakeLock.request('screen');return { wakeLock };
} catch (error) {
return { error };
}
};test('wakeLock request with success', async () => {
const { wakeLock, error } = await requestWakeLock(handleRelease);expect(error).not.toBeDefined();
expect(wakeLock).toBeDefined();
expect(wakeLock?.type).toEqual('screen');
expect(wakeLock?.released).toBe(false);
});
```## Author
👤 **Joris**
- Twitter: [@\_jorisre](https://twitter.com/_jorisre)
- Github: [@jorisre](https://github.com/jorisre)## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/jorisre/jest-wake-lock-mock/issues).## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2020 [Joris](https://github.com/jorisre).
This project is [MIT](https://github.com/jorisre/jest-wake-lock-mock/blob/master/LICENSE) licensed.---
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_