New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dancrumb/testify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dancrumb/testify

Sometimes you have a function in a file that is private, but needs to be tested.

  • 1.3.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

testify

Sometimes you have a function in a file that is private, but needs to be tested.

Exporting it into a production environment can result in pierced abstractions, which defeats the purpose of abstraction.

testify allows you to export a wrapped version of a private function. While the function is still exported, attempts to use it in production will result in a thrown Error.

Example

// library.ts
const privateFunction = () => {
    // Something happens here
};

const _testableFunction = testify(privateFunction);

export {_testableFunction};

_testableFunction can be used in your tests (i.e. when process.env.NODE_ENV === 'test'), but will throw in production.

Why not use rewire?

The rewire package approaches this problem via monkey-patching. The problem with that is that you lose visibility of code coverage on your rewired functions.

This approach allows you to get the coverage data you need.

FAQs

Package last updated on 19 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc