Fredastaire
Fredastaire adds step methods to mocha tests that have two impacts:
- Your test cases' setup code is significantly more readable
- You only have to write the same setup steps once
Table of contents
Setup
npm install fredastaire --save-dev
oryarn add fredastaire -D
- Define your steps wherever you like. (example below)
- Write some tests that use
given
. (example below) - Run your tests with the fredastaire ui, requiring your steps file:
mocha ./tests/some-tests.js --ui fredastaire --require <your steps file>
Usage
1. Tests
Just call given('with some string')
. The string will be used to identify which step definition to call (more on that later).
There's also when
and and
, which are aliases of given
.
TODO: Add given, when, and to the test output.
// /your/project/tests/astronauts-test.js const state = spaceThings: astronauts: ; let res; ;
2. Step definitions
Step definitions are the places where you put your setup code for individual tests.
// /your/project/wherever/you/like/your-definitions.js const addSteps = ;const request = ; ;
Full API
Methods
given
, and
, when
;
Calls a defined step inside a before
. given
, and
and when
are all the
same function, so use them in whatever order you like. Return a promise to
handle async behavior.
Arguments
name
-- The name used to identify the step.
{string} So if you define a step named "this is a step", then you would run the step
using given('this is a step')
.
data
-- Whatever you need to pass to the step.
{object} Pass whatever your step needs to can create something specific.
addSteps
;
Registers steps which are triggered with given
.
Arguments
steps
-- The name and function to be triggered by given
.
{object} The objects you pass to addSteps
are all merged together, so when you call given(name)
, it calls steps[name]()
. *So if you pass the same key twice to addSteps
, the first step will be replaced by the second.
getSteps()
Gets all the steps you've defined