-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Comments
I know TDD but do not understand what do you need from API. The simplest mock is just calling Do you have some examples of other state manager, how they explain usage in TDD? |
Moved to #182 |
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);
});
});
}); But not sure if i this is the best way or not. |
Please add some doc about how to mock it and how to use it while following TDD.
The text was updated successfully, but these errors were encountered: