Cyclone-Mock-Store is a testing tools for Cyclone.
Here is an example of a test.
const assert = require('power-assert');
import { createMockStore } from '@ushiboy/cyclone-mock-store';
const { mockDispatcher } = createMockStore();
function increment() {
return { type: 'increment' };
}
function greet() {
return async ({ fetchMessage }) => {
return {
type: 'greeting',
payload: {
message: await fetchMessage()
}
};
};
}
describe('actions', function() {
describe('increment', () => {
it('should returns "increment" type of action', async () => {
const store = mockDispatcher();
await store.dispatch(increment());
const [a] = store.getActions();
assert(a.type === 'increment');
});
});
describe('greet', () => {
let store;
beforeEach(() => {
store = mockDispatcher({
async fetchMessage() {
return 'hello';
}
});
});
it('should returns "greeting" type of action', async () => {
await store.dispatch(greet());
const [a] = store.getActions();
assert(a.type === 'greeting');
});
it('should returns payload of message', async () => {
await store.dispatch(greet());
const [a] = store.getActions();
assert(a.payload.message === 'hello');
});
});
});
It return a MockAPI
.
createMockStore(): MockAPI
It is an API that mocks the Store
.
type MockAPI = {
mockDispatcher<E, A>(extra: ?E): MockStore<E, A>
};
It create and return a MockStore
from the extra argument.
mockDispatcher<E, A>(extra: ?E): MockStore<E, A>
Record the actions executed.
type MockStore<E, A> = {
dispatch(a: A | Promise<A> | (e: E) => (A | Promise<A>)): Promise<void>,
getActions(): Array<A>,
clearActions(): void
};
It execute Action
against MockStore
.
dispatch(a: A | Promise<A> | (e: E) => (A | Promise<A>)): Promise<void>
It returns the recorded actions.
getActions(): Array<A>
It clear the recorded actions.
clearActions(): void
Initial Cyclone-Mock-Store release.
MIT