Skip to content

Instantly share code, notes, and snippets.

View Julianhm9612's full-sized avatar
💭
Make it happen!

Julian Henao Marin Julianhm9612

💭
Make it happen!
View GitHub Profile
@Julianhm9612
Julianhm9612 / index.test.tsx
Last active March 7, 2024 20:02
Jest - Mock useMutation
// Method 1
jest.mock('react-query', () => ({
useMutation: jest.fn()
}));
const mockMutationFn = jest.fn().mockRejectedValue(new Error('Mutation failed'));
(useMutation as jest.Mock).mockReturnValue([mockMutationFn, {}]);
expect(actionCreatorsModal.setIsError).toHaveBeenCalledWith(true, expect.any(Object));
@Julianhm9612
Julianhm9612 / index.test.tsx
Last active February 5, 2024 21:52
Jest - Mock custom hook
// Method 1
const mockData = {
something: 'value'
};
const mockUseSomething = jest.fn().mockReturnValue({
data: mockData,
isLoading: false,
isSuccess: true,
refetch: () => mockUseSomething
@Julianhm9612
Julianhm9612 / index.test.tsx
Last active February 5, 2024 21:43
Jest - Mock useQuery
// Method 1
const mockRefetch = jest.fn();
jest.mock('react-query', () => ({
useQuery: jest.fn().mockReturnValue(({ data: { ...MockData }, isLoading: false, isSuccess: true, refetch: () => mockRefetch }))
}));
// Method 2
const mockRefetch = jest.fn();
@Julianhm9612
Julianhm9612 / index.js
Last active February 5, 2024 21:07
Sleep
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
// Sleep a second
sleep(1000).then(() => {
// Code to run after
});
@Julianhm9612
Julianhm9612 / index.test.tsx
Created February 2, 2024 19:48
Jest - Mock dispatch
const dispatch = jest.fn();
const state = { ... };
render(
<SomeContext.Provider value={{ state, dispatch }}>
<Component />
</SomeContext.Provider>
);
// Call a button or somtheing
@Julianhm9612
Julianhm9612 / index.test.tsx
Created February 2, 2024 19:44
Jest - Spy useState
const setState = jest.fn();
const useStateSpy = jest.spyOn(React, 'useState');
useStateSpy.mockImplementation(() => [init, setState]);
expect(setState).toHaveBeenCalledWith('S');
@Julianhm9612
Julianhm9612 / zen_python.md
Created April 29, 2019 18:55 — forked from pyjavo/zen_python.md
El zen de Python: Explicado y con ejemplos

El Zen de Python

Si alguna vez abren la consola de python y escriben import this verán que les aparecerán las líneas con el famoso Zen de Python:

  1. Beautiful is better than ugly.
  2. Explicit is better than implicit.
  3. Simple is better than complex.
  4. Complex is better than complicated.
  5. Flat is better than nested.
  6. Sparse is better than dense.
it('Validate the images displayed', () => {
cy.get('.v-image__image').each(($el) => {
const image = $el.css('background-image').replace('url("', '').replace('")', '')
cy.request(image).then((res) => {
expect(res.status).to.eql(200);
});
});
});
it('Validate the images displayed', () => {
@Julianhm9612
Julianhm9612 / install.md
Created January 7, 2020 21:06 — forked from Ryanb58/install.md
How to install telnet into a alpine docker container. This is useful when using the celery remote debugger in a dev environment.
>>> docker exec -it CONTAINERID /bin/sh
/app # telnet
/bin/sh: telnet: not found

/app # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
v3.7.0-243-gf26e75a186 [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.0-229-g087f28e29d [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]
@Julianhm9612
Julianhm9612 / install.md
Created January 7, 2020 21:06 — forked from Ryanb58/install.md
How to install telnet into a alpine docker container. This is useful when using the celery remote debugger in a dev environment.
>>> docker exec -it CONTAINERID /bin/sh
/app # telnet
/bin/sh: telnet: not found

/app # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
v3.7.0-243-gf26e75a186 [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.0-229-g087f28e29d [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]