forked from Qortal/q-blog
30 lines
925 B
TypeScript
30 lines
925 B
TypeScript
import React from 'react';
|
|
import { describe, it, expect } from 'vitest';
|
|
import { Provider } from 'react-redux';
|
|
import { store } from '@/state/store';
|
|
import { render } from '@testing-library/react';
|
|
import { useFetchPosts } from '@/hooks/useFetchPosts';
|
|
|
|
function Harness({ onReady }: { onReady: (api: ReturnType<typeof useFetchPosts>) => void }) {
|
|
const api = useFetchPosts();
|
|
React.useEffect(() => {
|
|
onReady(api);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
return null;
|
|
}
|
|
|
|
describe('useFetchPosts', () => {
|
|
it('checkAndUpdatePost returns true for new posts', () => {
|
|
let api!: ReturnType<typeof useFetchPosts>;
|
|
render(
|
|
<Provider store={store}>
|
|
<Harness onReady={(a) => (api = a)} />
|
|
</Provider>,
|
|
);
|
|
|
|
const p = { id: '1', user: 'u', title: 't', description: 'd', createdAt: 0 };
|
|
expect(api.checkAndUpdatePost(p as any)).toBe(true);
|
|
});
|
|
});
|