API
Helpers
The sazerac
module exports 3 helper functions:
import { test, given, forCases } from 'sazerac' |
test(testFn, definerFn)
Defines test cases for a function
Arguments:
{Function} testFn
- a function to test{Function} definerFn
- a function that defines test cases fortestFn
Example:
test(mySumFunction, () => { |
given([…args])
Defines the functional arguments for a test case
Arguments:
{...object} args
- arguments that will be passed to the function being tested
Returns:
{TestCase}
Example:
test(mySumFunction, () => { |
forCases(…testCases)
Groups multiple test case objects into a collection
Arguments:
{...TestCase | Array<TestCase>} testCases
Returns:
{TestCaseCollection}
Example:
test(isPrime, () => { |
TestCase | TestCaseCollection
The TestCase
and TestCaseCollection
objects have an identical API:
expect(value, [message])
Defines the expected return value for the test case. Uses chai assert.deepEqual()
to assert that the expected return value equals the actual return value.
Arguments:
{object} value
- expected return value{string} message
- describes the test case expectation
Returns:
{TestCase | TestCaseCollection}
Example:
test(mySumFunction, () => { |
expectError(errorMessage, [message])
Defines an expected error to be thrown when this test case is executed.
Arguments:
{object} errorMessage
- expected message from the error thrown{string} message
- describes the test case expectation
Returns:
{TestCase | TestCaseCollection}
Example:
function throwAnError(msg) { |
describe(message)
Defines a describe message for the test case.
Arguments:
{string} message
Returns:
{TestCase | TestCaseCollection}
Example:
test(mySumFunction, () => { |
should(message)
Defines a message to describe the test case assertion. This message is passed to the it
function when the test is executed.
Arguments:
{string} message
Returns:
{TestCase | TestCaseCollection}
Example:
test(mySumFunction, () => { |
assert(message, assertFn)
Defines a custom assertion for the test case
Arguments:
{string} message
- describes the assertion{Function} assertFn
- function for defining the assertion. Receives the actual return value of the function being tested as its only argument.
Returns:
{TestCase | TestCaseCollection}
Example:
test(mySumFunction, () => { |
before(beforeFn)
Adds a function to run before a test case is executed
Arguments:
{Function} beforeFn
- function to run before the test case
Returns:
{TestCase | TestCaseCollection}
Example:
import sinon from 'sinon' |
after(afterFn)
Adds a function to run after a test case is executed
Arguments:
{Function} afterFn
- function to run after the test case
Returns:
{TestCase | TestCaseCollection}
Example:
import sinon from 'sinon' |