1.0.32 • Published 3 years ago

jest-marmot v1.0.32

Weekly downloads
29
License
MIT
Repository
github
Last release
3 years ago

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", "test@jest-marmot.com")
    .click({testId: "submit"})
    .see("Welcome, " + "test@jest-marmot.com")
    .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

1.0.32

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago