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

detox-jest-spy

v1.0.1

Published

[![CircleCI](https://circleci.com/gh/8fit/detox-jest-spy.svg?style=svg)](https://circleci.com/gh/8fit/detox-jest-spy)

Downloads

546

Readme

CircleCI

The problem

The detox framework allows us to orchestrate the application interaction, and to make assertions on the state of the interface.

As part of our testing strategy, we sometimes want to test certain critical side effects, such as analytics events being fired correctly as a result of interacting with the interface. Since detox is a greybox testing framework we're able to make some small changes to make this possible.

This library assumes jest as the test runner, but the same thing should work in the same manner for mocha.

Approach

We use Detox mocking to replace certain objects or functions with proxies that will track calls and inform the spy server. The spy server parleys this information into calls on jest Mocks, which can then be used for assertions within the Detox test context.

detox jest spy

Install

npm install --save detox-jest-spy

Usage

The first thing we'll do is use Detox mocking to replace a file with the detox proxy implementation.

For example if you have a file such that

// analytics.js

export default {
  trackAction: () => {
    /* the usual implementation */
  },
  trackScreen: () => {
    /* the usual implementation */
  }
};

We'll add a file alongside it with the .e2e.js extension.

// analytics.e2e.js
import { getProxy } from "detox-jest-spy/dist/client";

export default getProxy("Analytics");

Ensure you add RN_SRC_EXT to your build commands as indicated in the docs so that the detox build will use the e2e.js file instead of the usual one.

Then you can write your detox tests:

// myfeature.smoke.spec.js

import { start, stop, getSpy } from "detox-jest-spy";
// detox overrides the global expect variable with it's own implementation, so we need to reimport it under another name
import default as jestExpect from 'expect';

beforeAll(() => {
  start(); // start the detox-jest-spy server
});

afterAll(() => {
  stop(); // stop the server after test run is complete
});

it("does somethin", async () => {
  // perform the usual detox UI orchetration
  await this.getElementById("myid").tap();

  // get the jest spy object
  const spy = getSpy("Analytics.trackAction");

  // use jest expect to perform assertions on the spy
  jestExpect(spy).toBeCalledWith({ id: 'myid' });
});