Skip to content

Commit

Permalink
Fix attaching action, after a spy is restored to the original impleme…
Browse files Browse the repository at this point in the history
…ntation
  • Loading branch information
kasperpeulen committed Mar 7, 2024
1 parent d6f8526 commit 1d76565
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion code/addons/actions/src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type { LoaderFunction } from '@storybook/types';
import { action } from './runtime';

export const tinySpyInternalState = Symbol.for('tinyspy:spy');

const attachActionsToFunctionMocks: LoaderFunction = (context) => {
const {
args,
Expand All @@ -15,7 +17,9 @@ const attachActionsToFunctionMocks: LoaderFunction = (context) => {
typeof value === 'function' && '_isMockFunction' in value && value._isMockFunction
)
.forEach(([key, value]) => {
const previous = value.getMockImplementation();
const previous =
value.getMockImplementation() ??
(tinySpyInternalState in value ? value[tinySpyInternalState]?.getOriginal() : undefined);
if (previous?._actionAttached !== true && previous?.isAction !== true) {
const implementation = (...params: unknown[]) => {
action(key)(...params);
Expand Down

0 comments on commit 1d76565

Please sign in to comment.