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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@openreachtech/jest-constructor-spy

v1.1.2

Published

`ConstructorSpy` is a module designed to spy on the constructor of JavaScript class in Jest. It allows developers to easily track and monitor the usage of the constructor in their Jest tests.

Readme

ConstructorSpy for Jest

ConstructorSpy is a module designed to spy on the constructor of JavaScript class in Jest. It allows developers to easily track and monitor the usage of the constructor in their Jest tests.

Installation

  • Node.js is required. If it is not installed yet, please do so before proceeding.

    | tools | version | | :-- | :-- | | Node.js | >= 20.0.0 | | npm | >= 10.0.0 |

  • A testing tool such as Jest is required. The following is an example of how to install Jest. If you prefer to use a different testing tool, please refer to its specific installation guide. Require Jest version 29.5.0 or greater.

    npm install --save-dev jest
  • Create a .npmrc file in the root directory of your project and add any necessary configurations. This might be required for installing certain npm packages.

  • Please add the following line to your .npmrc file.

    @openreachtech:registry=https://npm.pkg.github.com
  • You can install ConstructorSpy with Jest version 29.5.0 or greater by the following command:

    npm install --save-dev @openreachtech/jest-constructor-spy

Usage

  • When you design a class with factory method, ConstructorSpy can test to call constructor from the factory method.
const { ConstructorSpy } = require('@openreachtech/jest-constructor-spy')

class Sample {
  constructor (value) {
    this.value
  }

  static createWithDefaultValue () {
    return new this(12000)
  }
}

test('to call constructor with 12000', () => {
  const SpiedSample = ConstructorSpy.create({ jest })
    .spyOn(Sample)

  SpiedSample.createWithDefaultValue()

  expect(SpiedSample.__spy__)
    .toHaveBeenCalledWith(12000)
})

Setup in jest.config.js

  • You can refer to an instance of ConstructorSpy by constructorSpy in each test by using the following in setupFilesAfterEnv in jest.config.js.
// jest.config.js

module.exports = {
  setupFilesAfterEnv: [
    ...

    '@openreachtech/jest-constructor-spy/config/setupAfterEnv.js',

    ...
  ], ...
}
// __tests__/test.js

class Sample {
  constructor (value) {
    this.value
  }

  static createWithDefaultValue () {
    return new this(12000)
  }
}

test('to call constructor with 12000', () => {
  const SpiedSample = constructorSpy.spyOn(Sample)

  SpiedSample.createWithDefaultValue()

  expect(SpiedSample.__spy__)
    .toHaveBeenCalledWith(12000)
})

License

This project is released under the MIT License.

For more details, please see in the LICENSE file.

Contribution

  • We welcome bug reports, feature requests, and code contributions. Please feel free to contact us through GitHub Issues or Pull Requests. Your contributions are highly appreciated!

Authors

  • Open Reach Tech Inc.

  • We strive to meet user expectations and welcome any kind of feedback.