Skip to content

Fix Storybook testing: clickMe.click is not a function #671

@melvincarvalho

Description

@melvincarvalho

Summary

Fixes the clickMe.click is not a function error in Storybook when rendering Tabs stories (particularly the selectedTab story).

Problem

In src/tabs.ts, the code calls .click() on firstChild without checking if it's actually an element with a click method:

const clickMe = tab.firstChild
// @ts-ignore
if (clickMe) clickMe.click()

firstChild returns ChildNode | null, which could be a Text node or Comment node (no .click() method). The @ts-ignore masked the TypeScript error but crashed at runtime.

Solution

Replace the unsafe code with proper type checking:

const clickMe = tab.firstChild as HTMLElement | null
if (clickMe?.click) clickMe.click()

Fixes

Closes #490

Testing

  • All existing tests pass
  • Storybook Tabs stories now render without error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions