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

Add some docs about TDD #153

Closed
kasir-barati opened this issue Feb 8, 2023 · 3 comments
Closed

Add some docs about TDD #153

kasir-barati opened this issue Feb 8, 2023 · 3 comments

Comments

@kasir-barati
Copy link

Please add some doc about how to mock it and how to use it while following TDD.

@ai
Copy link
Member

ai commented Feb 8, 2023

I know TDD but do not understand what do you need from API.

The simplest mock is just calling store.set(mockData)

Do you have some examples of other state manager, how they explain usage in TDD?

@ai ai changed the title Add some dock about TDD Add some docs about TDD Apr 17, 2023
@ai
Copy link
Member

ai commented Apr 17, 2023

Moved to #182

@ai ai closed this as completed Apr 17, 2023
@kasir-barati
Copy link
Author

I know TDD but do not understand what do you need from API.

The simplest mock is just calling store.set(mockData)

Do you have some examples of other state manager, how they explain usage in TDD?

I already do it like this:

import { AxiosInstance, AxiosResponse } from 'axios';
import { allTasks, cleanStores, keepMount } from 'nanostores';
import {
    afterEach,
    beforeEach,
    describe,
    expect,
    it,
    vi,
} from 'vitest';
import { SummariesStateStore } from './Summaries.store';
import summaries from './summaries.dummy-data.json';

describe('SummariesStateStore', () => {
    const { states, actions } = SummariesStateStore;
    const mockedAxiosInstance: AxiosInstance =
        {} as Partial<AxiosInstance> as AxiosInstance;

    afterEach(() => {
        cleanStores(states.accordionIndex, states.summaries);
        states.accordionIndex.set(undefined);
        states.summaries.set([]);
    });

    describe('accordionIndexState', () => {
        beforeEach(() => {
            keepMount(states.accordionIndex);
        });

        it('should return 1 ', async () => {
            actions.setAccordionIndex(1);
            await allTasks();

            expect(states.accordionIndex.get()).toBe(1);
        });
    });

    describe('summaries', () => {
        it('should fetch summaries', async () => {
            mockedAxiosInstance.get = vi.fn().mockResolvedValueOnce({
                data: summaries,
            } as AxiosResponse);
            await actions.fetchSummaries(mockedAxiosInstance);
            await allTasks();

            expect(states.summaries.get()).toBe(summaries);
        });
    });
});

Ref: https://github.com/kasir-barati/open-ai-summaries/blob/main/apps/chrome/src/components/Summaries/Summaries.store.spec.ts

But not sure if i this is the best way or not.

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

No branches or pull requests

2 participants