diff --git a/code/lib/preview-api/src/modules/store/csf/testing-utils/index.ts b/code/lib/preview-api/src/modules/store/csf/testing-utils/index.ts index 13cf81424441..955c19eec9f2 100644 --- a/code/lib/preview-api/src/modules/store/csf/testing-utils/index.ts +++ b/code/lib/preview-api/src/modules/store/csf/testing-utils/index.ts @@ -21,7 +21,7 @@ import { normalizeComponentAnnotations } from '../normalizeComponentAnnotations' import { getValuesFromArgTypes } from '../getValuesFromArgTypes'; import { normalizeProjectAnnotations } from '../normalizeProjectAnnotations'; -let GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS = {}; +let GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS = composeConfigs([]); export function setProjectAnnotations( projectAnnotations: ProjectAnnotations | ProjectAnnotations[] @@ -33,7 +33,7 @@ export function setProjectAnnotations( export function composeStory( storyAnnotations: LegacyStoryAnnotationsOrFn, componentAnnotations: ComponentAnnotations, - projectAnnotations: ProjectAnnotations = GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS, + projectAnnotations: ProjectAnnotations = GLOBAL_STORYBOOK_PROJECT_ANNOTATIONS as ProjectAnnotations, defaultConfig: ProjectAnnotations = {}, exportsName?: string ): PreparedStoryFn> { @@ -60,7 +60,7 @@ export function composeStory({ ...projectAnnotations, ...defaultConfig, }); diff --git a/code/renderers/react/src/__test__/composeStories.test.tsx b/code/renderers/react/src/__test__/composeStories.test.tsx index ad5543822b19..8c97d906ab22 100644 --- a/code/renderers/react/src/__test__/composeStories.test.tsx +++ b/code/renderers/react/src/__test__/composeStories.test.tsx @@ -9,8 +9,6 @@ import { setProjectAnnotations, composeStories, composeStory } from '..'; import type { Button } from './Button'; import * as stories from './Button.stories'; -setProjectAnnotations([]); - // example with composeStories, returns an object with all stories composed with args/decorators const { CSF3Primary } = composeStories(stories); @@ -43,15 +41,15 @@ test('reuses args from composeStories', () => { expect(buttonElement).not.toBeNull(); }); -describe('GlobalConfig', () => { - test('renders with default globalConfig', () => { +describe('projectAnnotations', () => { + test('renders with default projectAnnotations', () => { const WithEnglishText = composeStory(stories.CSF2StoryWithLocale, stories.default); const { getByText } = render(); const buttonElement = getByText('Hello!'); expect(buttonElement).not.toBeNull(); }); - test('renders with custom globalConfig', () => { + test('renders with custom projectAnnotations via composeStory params', () => { const WithPortugueseText = composeStory(stories.CSF2StoryWithLocale, stories.default, { globalTypes: { locale: { defaultValue: 'pt' } } as any, }); @@ -59,6 +57,12 @@ describe('GlobalConfig', () => { const buttonElement = getByText('Olá!'); expect(buttonElement).not.toBeNull(); }); + + test('renders with custom projectAnnotations via setProjectAnnotations', () => { + setProjectAnnotations([{ parameters: { injected: true } }]); + const Story = composeStory(stories.CSF2StoryWithLocale, stories.default); + expect(Story.parameters?.injected).toBe(true); + }); }); describe('CSF3', () => {