Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose mocks for testing #1968

Open
lr-mjaouen opened this issue Mar 3, 2023 · 4 comments
Open

Expose mocks for testing #1968

lr-mjaouen opened this issue Mar 3, 2023 · 4 comments
Labels
feature New capability

Comments

@lr-mjaouen
Copy link

lr-mjaouen commented Mar 3, 2023

Motivation
I may have miss it? but would it be possible to expose mocks for testing?
Or what are your recommendation for testing?
How do you bypass following warnings or furnish the providers (so far I mock component & hooks from gs to just render anything & do nothing),

The useChannelStateContext hook was called outside of the ChannelStateContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the Window component.
The useChannelStateContext hook was called outside of the ChannelStateContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the Window component.

Thank you.

Proposed solution
channel mock builder exposed,
Client / Channel components mocks? (like Apollo client for instance https://www.apollographql.com/docs/react/development-testing/testing/)

MessageList/VirtualMessageList mocked component?

Acceptance Criteria

@lr-mjaouen lr-mjaouen added the feature New capability label Mar 3, 2023
@MartinCupela
Copy link
Contributor

Hello @lr-mjaouen , we do not expose mocks. Could you provide an example, where you find yourself in need of such mocks, please?

@lr-mjaouen
Copy link
Author

lr-mjaouen commented Mar 10, 2023

Hello,
Mainly for testing purposes.
(I remember in previous versions mocking the channel previously)
Also for testing custom components (CustomInput, CustomMessage, CustomTimeSeparator etc).
Exposing for instance aMessage({overrides}), aChannel({overrides}) would be useful and I saw you already have it?
And maybe helpers too, like a context/Channel component already provided etc.
Now moment I mock it myself (I'm not able to mock it properly anymore & pass it to de Channel component for instance), I just hard mock the components/hooks directly to avoid issues in my tests (hook usage without context warning etc).

vi.mock('stream-chat-react', async () => {
    const streamChatActual = await vi.importActual<typeof import('stream-chat-react')>('stream-chat-react');
    return {
        ...streamChatActual,
        MessageList: vi.fn(() => <></>),
        VirtualizedMessageList: vi.fn(() => <></>),
        Window: vi.fn(() => <></>),
        MessageInput: vi.fn(() => <></>),
        Channel: vi.fn(({ children }) => <>{children}</>),
        useChannelActionContext: vi.fn(),
    };
});

Not optimal. Could be useful to have default mocks (Messages, Channels, Attachements etc).

@MartinCupela
Copy link
Contributor

@lr-mjaouen for now we do not plan to support maintenance of mocks. The situation may change in the future with priorities shifting. We will keep this as a feature request.

@charliedavison
Copy link

charliedavison commented Aug 1, 2023

I've run into this issue as well, it would really help us to be able to get access to these ready-made mocks rather than having to try and create them ourselves. The use case for us specifically is where we are wanting to test components that are overriding the defaults like a custom message input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New capability
Projects
None yet
Development

No branches or pull requests

3 participants