This commit is contained in:
Norbert de Langen 2020-03-13 11:52:11 +01:00
parent cc7b7e5ac7
commit b7168d556e
No known key found for this signature in database
GPG Key ID: 976651DA156C2825
2 changed files with 6 additions and 13 deletions

View File

@ -10,12 +10,10 @@ export interface SubAPI {
}
export const init: ModuleFn = ({ store, fullAPI }) => {
const updateGlobalArgs = (newGlobalArgs: Args) => {
fullAPI.emit(UPDATE_GLOBAL_ARGS, newGlobalArgs);
};
const api: SubAPI = {
updateGlobalArgs,
updateGlobalArgs(newGlobalArgs) {
fullAPI.emit(UPDATE_GLOBAL_ARGS, newGlobalArgs);
},
};
const state: SubState = {

View File

@ -2,7 +2,7 @@ import EventEmitter from 'event-emitter';
import { UPDATE_GLOBAL_ARGS, GLOBAL_ARGS_UPDATED } from '@storybook/core-events';
import { ModuleArgs, API } from '../index';
import { init as initModule } from '../modules/globalArgs';
import { init as initModule, SubAPI } from '../modules/globalArgs';
function createMockStore() {
let state = {};
@ -11,14 +11,9 @@ function createMockStore() {
setState: jest.fn().mockImplementation(s => {
state = { ...state, ...s };
}),
}; // as unknown) as Module['store'];
};
}
// function createMockModule() {
// // This mock module doesn't have all the fields but we don't use them all in this sub-module
// return ({ as unknown) as Module;
// }
describe('stories API', () => {
it('sets a sensible initialState', () => {
const store = createMockStore();
@ -55,7 +50,7 @@ describe('stories API', () => {
init();
api.updateGlobalArgs({ a: 'b' });
(api as SubAPI).updateGlobalArgs({ a: 'b' });
expect(fullAPI.emit).toHaveBeenCalledWith(UPDATE_GLOBAL_ARGS, { a: 'b' });
});
});