Marty's test utils are available by requiring marty/test-utils. For full examples see marty-test-examples.
var TestUtils = require('marty/test-utils');
var app = TestUtils.createApplication(Application, {
...
});createApplication(ApplicationType, options)
Creates an instance of the application with the given type while giving you the opportunity to control what actually gets instantiated.
Options
var TestUtils = require('marty/test-utils');
var app = TestUtils.createApplication(Application, {
include: ['foo', 'bar'],
exclude: ['bar', 'baz'],
stub: {
fooAPI: {
getFoo: sinon.stub().returns(Promise.done({ id: 123 }))
}
}
});| Name | type | description |
|---|---|---|
| stub | object | When registering, instead of creating an instance of the type it will use the stub instead |
| include | string array | Will only create instances with Ids that are in this array |
| include | string array | Will only create instances with Ids that are not in this array |
createStore(properties)
Creates a mock store with the given properties. Useful when stubbing out a store.
var app = TestUtils.createApplication(Application, {
stub: {
fooStore: TestUtils.createStore({
getFoo: sinon.stub()
})
}
});dispatch(app, type, ...args)
Dispatches an action with given type and arguments from the applications dispatcher.
var app = new Application();
TestUtils.dispatch(app, "RECEIVE_USER", { id: 123 });getDispatchedActionsWithType(app, type)
Returns all actions that have been dispatched with that type.
var actions = TestUtils.getDispatchedActionsWithType(app, "RECEIVE_USER");hasDispatched(app, type, ...args)
Returns true if an action with the given type and arguments has been dispatched.
expect(TestUtils.hasDispatched(app, "RECEIVE_USER", { id: 123 })).to.be.true;