state-definition provides late-binding and memoization for state definitions in tests. It was inspired by RSpec's
- Properties defined can reference other properties in the state definition.
- Properties can be defined as functions, but are accessed as properties.
- Properties are evaluated as-needed. This means that if you redefine a state property like we do with isGroupAdmin, its value will bubble up to other properties when they are referenced in tests.
- Property values are memoized. Once evaluated, functions that define properties will not be called again. This is useful when state definitions involve stateful operations like creating a database entry or rendering a React component with Enzyme.
Initialize StateDefinition with an object of property definition expressions. Definitions can either be simple expressions or functions. Functions take the StateDefinition object itself as the first parameter. The StateDefinition object is also the
this context in definition functions.
Redefine StateDefinition properties by calling
define in nested describe functions.
Simply refer to any StateDefinition property by the key name irrespective of if the property was defined as a simple expression or a function.