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

jest-marmot

v1.0.32

Published

Jest Test Framework DSL

Downloads

41

Readme

jest-marmot

JS Integration Test DSL

Heavily inspired by the RoR testing frameworks

NPM Version Linux Build

Install

npm i --save-dev jest-marmot

Usage

For a full redux/react-router example, see the redux test app.

import Marmot, {scenario} from 'jest-marmot'
import {MyRootComponent} from 'myRootComponent'

Marmot.root(() => <MyRootComponent />)

describe("My Feature", () => {
  scenario("My specific scene")
    .see("Hey Fella")
    .fillIn("Email", "[email protected]")
    .click({testId: "submit"})
    .see("Welcome, " + "[email protected]")
    .run()
})

Advanced Setup

Redux/ReactRouter w/ global setup

You'll want to configure Marmot global settings in your jest setup file.

e.g. in setupTests.js - configured from your package.json

import React from 'react'
import Marmot from "jest-marmot"
import App from "./App.js"
import React from 'react'

// If you use react-router + history
import { MemoryRouter as Router } from 'react-router-dom'
import history from "singletonHistoryFile"

// If you use Redux/Thunk
import { applyMiddleware, createStore }  from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'

// You're actual root reducer
import reducer from '../reducers/rootReducer'
import Mocks from 'yourDbApiMock'

// Setup/teardown your db/api mock
Marmot.on('begin')(opts => opts.data && Mocks.mockBackend(opts.data))
Marmot.on('cleanup')(() => Mocks.reset())

// Set root to be first non-Provider-wrapped component at top-level
Marmot.root(() => <App />) 

// Let Marmot know what to use when 'visiting' a url
Marmot.router(() => history)

// Provider wrappers to be layered onto our rendered root
Marmot.renderer((component, options) => <Router>{component}</Router>)
Marmot.renderer((component, options) => <Provider>{child}</Router>)

Then in your tests, you can simply...

import {scenario} from 'jest-marmot'

scenario("My test which assumes App is our entry point")
  .see("Homepage content")
  .click("Have A Go!")
  .see("Had a Went!")
  .run()

Reusable steps/flows

An argument could be made that reusable flows are a sign of redundant testing with a need for a more balanced test pyramid. Alas, you may not have a choice in a large existing test suite! Marmot's step array support is just what the doctor ordered!

In your tests, you could do something like this.

import {scenario} from 'jest-marmot'
import common from './steps/common'

scenario("A tour by an anonymous visitor")
  .see("Homepage content")
  .steps(common.tour)
  .see("Thanks for taking the tour")
  .run()

scenario("A tour by an identified user")
  .see("Homepage content")
  .fillIn("Name", "Billy")
  .steps(common.tour)
  .see("Thanks for taking the tour, Billy")
  .run()

Then, in ./steps/common.js

export default common = ({
  tour: [
    ["click", "Start Tour"],
    ["see", "Step 1"],
    ["click", "Proceed"],
    ["see", "Step 2"],
    ["click", "Finish"],
  ]
})

Troubleshooting

License

MIT