Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsJPeschel committed Apr 4, 2024
1 parent b119739 commit eba7036
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 84 deletions.
7 changes: 2 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript'
],
};
presets: [['@babel/preset-env', {targets: {node: 'current'}}], '@babel/preset-typescript']
};
2 changes: 1 addition & 1 deletion hooks/useCommonContext/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useCommonContext';
export * from './useCommonContext';
17 changes: 10 additions & 7 deletions hooks/useCommonContext/useCommonContext.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export function useCommonContext<T>(...contextHooks: (() => T)[]): T {
const context = contextHooks.reduce((prev, useContext) => {
try {
return useContext();
} catch {
return prev;
}
}, undefined as T | undefined);
const context = contextHooks.reduce(
(prev, useContext) => {
try {
return useContext();
} catch {
return prev;
}
},
undefined as T | undefined
);

if (!context) {
throw new Error('contexts not available');
Expand Down
2 changes: 1 addition & 1 deletion hooks/useFocus/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useFocus';
export * from './useFocus';
4 changes: 2 additions & 2 deletions hooks/useLoadData/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './useLoadData'
export * from './types';
export * from './useLoadData';
export * from './types';
108 changes: 54 additions & 54 deletions hooks/useLoadData/useLoadData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,61 +385,61 @@ describe('useLoadData', () => {
});

it('should re-invoke fetchData when fetchWhenDepsChange with an initial promise with normal dep', async () => {
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>('a');
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});
expect(result.current.loadedData.isInProgress).toBe(true);

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep('b'));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);

expect(getSuccess).toHaveBeenCalledWith('b');
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>('a');
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});

it('should re-invoke fetchData when fetchWhenDepsChange with an initial promise with finished dependency', async () => {
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>({...successfulResponse, result: 'a'});
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});
expect(result.current.loadedData.isInProgress).toBe(true);

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep({...successfulResponse, result: 'b'}));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);
expect(getSuccess).toHaveBeenCalledWith('b');
expect(result.current.loadedData.isInProgress).toBe(true);

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep('b'));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);

expect(getSuccess).toHaveBeenCalledWith('b');
});

it('should re-invoke fetchData when fetchWhenDepsChange with an initial promise with finished dependency', async () => {
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>({...successfulResponse, result: 'a'});
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});

it('should re-invoke fetchData when fetchWhenDepsChange with an initial promise with pending dependency', async () => {
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>(pendingResponse);
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});
expect(result.current.loadedData.isInProgress).toBe(true);
await act(() => result.current.setDep({...successfulResponse, result: 'a'}));

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep({...successfulResponse, result: 'b'}));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);
expect(getSuccess).toHaveBeenCalledWith('b');
expect(result.current.loadedData.isInProgress).toBe(true);

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep({...successfulResponse, result: 'b'}));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);
expect(getSuccess).toHaveBeenCalledWith('b');
});

it('should re-invoke fetchData when fetchWhenDepsChange with an initial promise with pending dependency', async () => {
const {result} = renderHook(() => {
const [dep, setDep] = useState<any>(pendingResponse);
const loadedData = useLoadData(getSuccess, [dep], {fetchWhenDepsChange: true});

return {loadedData, setDep};
});
expect(result.current.loadedData.isInProgress).toBe(true);
await act(() => result.current.setDep({...successfulResponse, result: 'a'}));

await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledWith('a');
expect(getSuccess).toHaveBeenCalledTimes(1);

await act(() => result.current.setDep({...successfulResponse, result: 'b'}));
await waitFor(() => expect(result.current.loadedData.isInProgress).toBe(false));
expect(getSuccess).toHaveBeenCalledTimes(2);
expect(getSuccess).toHaveBeenCalledWith('b');
});
});
2 changes: 1 addition & 1 deletion hooks/useOptionalDependency/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useOptionalDependency';
export * from './useOptionalDependency';
2 changes: 1 addition & 1 deletion hooks/useRetry/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useRetry';
export * from './useRetry';
15 changes: 7 additions & 8 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = {
singleQuote: true,
printWidth: 120,
bracketSpacing: false,
arrowParens: 'always',
tabWidth: 2,
trailingComma: 'none',
endOfLine: 'auto'
singleQuote: true,
printWidth: 120,
bracketSpacing: false,
arrowParens: 'always',
tabWidth: 2,
trailingComma: 'none',
endOfLine: 'auto'
};

6 changes: 3 additions & 3 deletions test-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const noop = () => {};
if(typeof window !== 'undefined') {
Object.defineProperty(window, 'scrollTo', {value: noop, writable: true})
}
if (typeof window !== 'undefined') {
Object.defineProperty(window, 'scrollTo', {value: noop, writable: true});
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "Node16",
"moduleResolution":"Node16",
"moduleResolution": "Node16",
"preserveSymlinks": true,
"rootDir": ".",
"outDir": "build/cjs",
Expand Down

0 comments on commit eba7036

Please sign in to comment.