Mock Screen Wake Lock API with ease

npm
GitHub Workflow Status
Codecov

License: MIT


Twitter: _jorisre

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

🏠 Homepage

Prerequisites

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

Author: Shantun Parmar

36 thoughts on “Mock Screen Wake Lock API with ease

  1. I enjoy reading an article that will make men and women think. Also, thank you for permitting me to comment. April Guilbert Shae

  2. Thank you and bless you, my friend. We are hearing and singing the same song. The Mother is growing stronger now and guides our hearts. Maddy Erhard Addi

  3. You made some good points there. I did a search on the issue and found most individuals will go along with with your blog. Janette Mischa Diarmuid

  4. Absolutely! Matt will be the first, well second, to know when copies arrive. Should be in two to three weeks. Dory Brok Shetrit

  5. I typically only use stock themes. It was something I slapped together in less then an hour. WordPress is good for such things. Madlin Elijah Heidie

  6. Hi there, this weekend is nice in support of me, since this point in time i am reading this wonderful informative article here at my house. Sigrid Kalil Richela

  7. What a material of un-ambiguity and preserveness of precious familiarity regarding unexpected feelings. Genny Maddie Smalley

  8. I really like this. It has been a while since I have posted a new Haibun Thinking due to time restraints. Claudine Thornton Venita

  9. Keep up the superb work , I read few articles on this site and I think that your website is real interesting and has sets of good information. Kaye Andras Cahra

  10. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  11. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  12. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  13. I precisely desired to say thanks again. I’m not certain the things I could possibly have created in the absence of the actual creative concepts discussed by you concerning my concern. It absolutely was a depressing concern for me personally, but considering a new professional fashion you handled it forced me to cry for delight. I’m grateful for the assistance and as well , expect you comprehend what a powerful job that you are carrying out educating men and women by way of a web site. I am certain you’ve never come across all of us.

Thanks for your support, You may click on ads to encourage us which assits to writers.

Leave a Reply

Your email address will not be published.