Skip to the main content


SpecHelpers

Generally useful helper functions for writing Jasmine unit tests.


SpecHelpers.withData(data, func)

Runs func as a test case multiple times, using entries from data as arguments. You can think of this as like Python’s DDT.

Parameters

data: object, An object mapping test names to arrays of function parameters. The name is passed to it() as the name of the test case, and the list of arguments is applied as arguments to func.

func: function, The function that actually expresses the logic of the test.

SpecHelpers.withConfiguration(config, setup, test)

Runs test multiple times, wrapping each call in a describe with beforeEach specified by setup and arguments and name coming from entries in config.

Parameters

config: object, An object mapping configuration names to arrays of setup function parameters. The name is passed to describe as the name of the group of tests, and the list of arguments is applied as arguments to setup.

setup: function, The function to setup the given configuration before each test case. Runs in beforeEach.

test: function, The function that actually express the logic of the test. May include it() or more describe().