@sutro-dev/testify
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

testify

npm (scoped) GitHub Workflow Status node-lts (scoped)

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.

/@sutro-dev/testify/

    Package Sidebar

    Install

    npm i @sutro-dev/testify

    Weekly Downloads

    270

    Version

    2.0.1

    License

    none

    Unpacked Size

    6.14 kB

    Total Files

    10

    Last publish

    Collaborators

    • sutro-dan
    • haydenski
    • dancrumb