Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
algarfer committed May 1, 2024
1 parent 0c4ff42 commit 5f53bbe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
24 changes: 0 additions & 24 deletions webapp/src/__test__/scripts/WebVitals.test.js

This file was deleted.

32 changes: 32 additions & 0 deletions webapp/src/__test__/scripts/reportWebVitals.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import reportWebVitals from '../../scripts/reportWebVitals';

jest.mock('web-vitals', () => ({
getCLS: jest.fn(),
getFID: jest.fn(),
getFCP: jest.fn(),
getLCP: jest.fn(),
getTTFB: jest.fn(),
}));

describe('reportWebVitals', () => {
afterEach(() => {
jest.clearAllMocks();
});

test('no hace nada si onPerfEntry no se proporciona', async () => {
const mockImport = jest.spyOn(import('web-vitals'), 'then');
await reportWebVitals();
expect(mockImport).not.toHaveBeenCalled();
});

test('no hace nada si onPerfEntry no es una función', async () => {
const mockImport = jest.spyOn(import('web-vitals'), 'then');
await reportWebVitals({});
expect(mockImport).not.toHaveBeenCalled();
});

test('no hace nada si onPerfEntry no es una función', async () => {
const mockImport = jest.spyOn(import('web-vitals'), 'then');
await reportWebVitals(function () {});
});
});
11 changes: 9 additions & 2 deletions webapp/src/__test__/views/Social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Social from '../../views/Social.jsx';
import { screen, waitFor, act } from '@testing-library/react';
import { customRender } from "../utils/customRenderer";
import React from 'react';
// import axios from "axios";
import axios from "axios";

const render = customRender((() => useAuth())())
// jest.mock('axios');
jest.mock('axios');
jest.mock('../../App.jsx', () => ({
useAuth: jest.fn().mockReturnValue({
getUser: jest.fn().mockReturnValue({
Expand All @@ -24,6 +24,13 @@ jest.mock('../../App.jsx', () => ({

describe('Social component', () => {

beforeAll(() => {
axios.get.mockReset();
axios.get.mockImplementation(() => Promise.resolve([{}]))
axios.post.mockReset();
axios.post.mockImplementation(() => Promise.resolve([{}]))
})

it('load component', async () => {
await act(async () => render(<Social />));

Expand Down

0 comments on commit 5f53bbe

Please sign in to comment.