1.1.0 ā€¢ Published 3 years ago

jest-wake-lock-mock v1.1.0

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

Mock Screen Wake Lock API (navigator.wakeLock) with ease and run your tests using Jest

šŸ  Homepage

Prerequisites

  • node >=10

Install

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 array and add jest-wake-lock-mock to it.

{
  setupFiles: ['jest-wake-lock-mock'],
  // jest config...
}

Tests

Write your tests with confidence using the same Screen Wake Lock API api as in the browser.

Example (More):

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

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2020 Joris. This project is MIT licensed.


This README was generated with ā¤ļø by readme-md-generator