Mock Screen Wake Lock API `navigator.wakeLock` with ease and run your tests using Jest
npm install jest-wake-lock-mock> Mock Screen Wake Lock API _(navigator.wakeLock)_ with ease and run your tests using Jest
- node >=10
``sh`
npm i -D jest-wake-lock-mockor
yarn add -D jest-wake-lock-mock
In your jest.config.js or package.json under jest section create a setupFiles array and add jest-wake-lock-mock to it.
`js`
{
setupFiles: ['jest-wake-lock-mock'],
// jest config...
}
Write your tests with confidence using the same Screen Wake Lock API api as in the browser.
Example (More):
`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);
});
``
š¤ Joris
- Twitter: @\_jorisre
- Github: @jorisre
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a āļø if this project helped you!
Copyright Ā© 2020 Joris.
This project is MIT licensed.
---
_This README was generated with ā¤ļø by readme-md-generator_