Add test-cases for config_api

This commit is contained in:
Arunoda Susiripala 2016-03-29 00:24:58 +05:30
parent 5c3955446d
commit 10936a7b4f
2 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,35 @@
const { describe, it } = global;
import { expect } from 'chai';
describe('client.ConfigApi', () => {
describe('_renderError', () => {
it('should send error stack and message to syncedStore');
});
describe('_renderMain', () => {
it('should run loaders if provided');
it('should set error in syncedStore to null');
it('should get a dump of storyStore and send it to syncedStore');
it('should set __updatedAt field with a updated value to syncedStore');
it('should select a new kind if the current one is not available');
describe('if there is kind', () => {
it('should select a new story if the current one is not available');
});
});
describe('configure', () => {
describe('initially', () => {
it('should call _renderMain with loaders');
describe('if caused an error', () => {
it('should call _renderError with the error');
});
});
describe('with hot reload', () => {
it('should call _renderMain with loaders');
describe('if caused an error', () => {
it('should call _renderError with the error');
});
});
});
});

View File

@ -4,7 +4,9 @@ export default class ConfigApi {
this._storyStore = storyStore;
}
_renderMain() {
_renderMain(loaders) {
if (loaders) loaders();
const data = this._syncedStore.getData();
data.error = null;
data.__updatedAt = Date.now();
@ -34,8 +36,7 @@ export default class ConfigApi {
configure(loaders, module) {
const render = () => {
try {
loaders();
this._renderMain();
this._renderMain(loaders);
} catch (error) {
this._renderError(error);
}