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

fixture-injection

v0.3.2

Published

A JavaScript test helper to inject fixtures

Downloads

36

Readme

fixture-injection

CircleCI

Note: fixture-injection is still in alpha stage.

fixture-injection is a test helper tool for Jest and Jasmine to define and use fixtures easily by leveraging dependency injection.

Fixtures are code that sets up test subjects and the testing environment defined as a value or a function. These fixtures can be injected to beforeAll(), it(), test(), etc. as arguments.

Usage

tests/__fixtures__.js:

// Example 1) Simple value
const foo = 'FOO'

// Example 2) Fixture function to provide a value which requires another fixture `foo`
const bar = (foo) => `BAR(${foo})`

// Example 3) Asynchronous fixture function to provide a value
const baz = async (provide, bar) => { // requires another fixture `bar`
  // Write setup code here
  await provide(`BAZ(${bar}`) // provide the value
  // `await` above waits until the context (test case or suite) finishes
  // Write teardown code here
}

module.exports = {
  foo,
  bar,
  baz
}

example.spec.js:

describe('My test suite', () => {
  let fixtures = {}

  beforeAll((foo) => { // Inject fixtures to *a suite* by beforeAll()
    fixtures.foo = foo
  })

  test('with fixtures', (bar, baz) => { // Inject fixtures to *a test case*
    // bar and baz are initialized just before this block
    const { foo } = fixtures // Get fixtures from the suite

    expect(foo).toEqual('FOO')
    expect(bar).toEqual('BAR(FOO)')
    expect(baz).toEqual('BAZ(BAR(FOO))')

    // bar and baz are released just after this block
  })

  // foo is released by hidden afterAll() of this block automatically
})

Features

  1. The code in the fixture function can do whatever you want
  2. Fixture function can be asynchronous and can have setup and teardown code around await provide()
  3. Fixtures are also available in other fixtures, and the dependencies are automatically resolved
    • Asynchronous fixtures are initialized concurrently as much as possible
  4. Local fixtures are initialized every time in each injected context
  5. Global fixtures are singletons and initialized only once
    • [Jest] They are initialized by Jest runner and will be sent to individual test workers via IPC
  6. In-line fixtures are also available by fixture() in each test file

Packages

Install/Setup

See the documentation of each test framework extension.

Related Work

  • pytest
    • pytest is a popular testing framework for Python. fixture-injection was inspired by its fixtures. pytest fixture has a scope (session/module/function) to manage its lifecycle and can be a generator to have setup/teardown logic in it.