npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-fix-undefined

v0.1.2

Published

References for Jest that are not packaged by default to solve the, `ReferenceError: Request is not defined` error.

Downloads

4,112

Readme

npm version Build Status install size

jest-fix-undefined

References for Jest that are not packaged by default to solve the, "ReferenceError: Request is not defined" error.

What problem is this solving?

If you have a Typescript project (have not tested on Javascript, same problem may exist) that uses Jest and you try to use the following objects in your test functions:

  • Nodejs Request
  • Nodejs Response
  • Nodejs Headers

You will receive an error message from Jest: ReferenceError: Request is not defined.

According to this Jest issue, this is a known limitation of Jest that you need to fix yourself. After reading this issue, this gave me some ideas on a fix for the Jest error message about _____ is not defined.

Personally, I am not a fan of randomly importing a npm module as a hack to fix issues. I knew that I would see this code, import 'isomorphic-fetch', in my Jest tests sometime in the future and wonder what on Earth that was there for. Also, adding isomorphic-fetch would cause bloat when I only need it for some references.

So instead, I decided to create my own hack. Create a repo dedicated to fixing this Jest undefined issue. A repo that is dedicated to fixing this issue while staying as slim as possible.

Getting started

  • npm install --save-dev jest-fix-undefined
  • Then, add import "jest-fix-undefined" to the top of your Jest test files.
  • The "ReferenceError: _______ is not defined" error should now be gone when running tests!

Author

Levi Bostian image

Contribute

jest-fix-undefined is open for pull requests. Check out the list of issues for tasks I am planning on working on. Check them out if you wish to contribute in that way.

Want to add to jest-fix-undefined? Before you decide to take a bunch of time and add functionality to the module, please, create an issue stating what you wish to add. This might save you some time in case your purpose does not fit well in the use cases of jest-fix-undefined.

If you find more types that throw ReferenceError by Jest, feel free to add them to this library and create a pull request! In order to make a pull request, you must add tests showing that ReferenceError is indeed thrown by Jest when trying to use it and that by using this library, it is fixed.

License

jest-fix-undefined is available under the MIT license. See the LICENSE file for more info.