mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 00:41:05 +08:00
Add a manager-side test
This commit is contained in:
parent
d03102ec00
commit
4bbeac786c
@ -18,7 +18,7 @@ const mockStories = jest.fn();
|
||||
jest.mock('../lib/events');
|
||||
jest.mock('global', () => ({
|
||||
...jest.requireActual('global'),
|
||||
fetch: jest.fn(() => ({ json: () => ({ v: 3, stories: mockStories() }) })),
|
||||
fetch: jest.fn(),
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
@ -58,6 +58,9 @@ const provider = { getConfig: jest.fn() };
|
||||
beforeEach(() => {
|
||||
provider.getConfig.mockReturnValue({});
|
||||
global.EventSource.reset();
|
||||
global.fetch
|
||||
.mockReset()
|
||||
.mockReturnValue({ status: 200, json: () => ({ v: 3, stories: mockStories() }) });
|
||||
});
|
||||
|
||||
describe('stories API', () => {
|
||||
@ -877,7 +880,23 @@ describe('stories API', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchStoryList', () => {
|
||||
describe('fetchStoryIndex', () => {
|
||||
it('deals with 500 errors', async () => {
|
||||
const navigate = jest.fn();
|
||||
const store = createMockStore();
|
||||
const fullAPI = Object.assign(new EventEmitter(), {});
|
||||
|
||||
global.fetch.mockReturnValue({ status: 500, text: async () => new Error('sorting error') });
|
||||
const { api, init } = initStories({ store, navigate, provider, fullAPI });
|
||||
Object.assign(fullAPI, api);
|
||||
|
||||
await init();
|
||||
|
||||
const { storiesConfigured, storiesFailed } = store.getState();
|
||||
expect(storiesConfigured).toBe(true);
|
||||
expect(storiesFailed.message).toMatch(/sorting error/);
|
||||
});
|
||||
|
||||
it('sets the initial set of stories in the stories hash', async () => {
|
||||
const navigate = jest.fn();
|
||||
const store = createMockStore();
|
||||
|
Loading…
x
Reference in New Issue
Block a user