Function | Clears Call History | Resets Implementations | Restores Original Implementation | Scope of Use |
---|---|---|---|---|
mockClear() |
✅ | ❌ | ❌ | Clear usage data of the mock function but keep its implementation and return values. |
mockReset() |
✅ | ✅ | ❌ | Reset the mock function to its initial state, removing any custom behavior or return values. |
mockRestore() |
✅ | ✅ | ✅ | Restore the original function, removing the mock (only applicable with jest.spyOn ). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { act, renderHook } from '@testing-library/react'; | |
import { describe, it, expect, beforeEach } from "vitest"; | |
import { usePostsStore } from "@/_store/usePostsStore"; | |
describe('usePostsStore', () => { | |
beforeEach(() => { | |
usePostsStore.getState().reset() | |
}); | |
it('should return the initial state', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, it, expect, beforeAll, afterEach, afterAll } from "vitest"; | |
import { GET } from "./route"; | |
import { createMockRequest, createTestServer } from "@/__tests__/utilities"; | |
import { http, HttpResponse } from "msw"; | |
const url = `${process.env.VITE_API_BASE_URL_V2}/posts`; | |
const mockPosts = [ { | |
"userId": 1, | |
"id": 2, | |
"title": "qui est esse", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, expect, it, vi } from "vitest"; | |
import { render, screen, fireEvent } from '@testing-library/react'; | |
import InputRadio from './InputRadio'; | |
describe('InputRadio Component Tests', () => { | |
const dummyProps = { | |
id: 'testRadio', | |
name: 'test-radio', | |
label: 'Test Label', | |
checked: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { describe, it, expect, vi } from "vitest"; | |
import { createRequest } from 'node-mocks-http'; | |
import { GET } from "./route"; | |
const mocks = vi.hoisted(() => ({ | |
get: vi.fn(), | |
})); | |
vi.mock("axios", async () => { | |
const actual: any = await vi.importActual("axios"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to sleep for a given duration | |
function triggerClick(element) { | |
const event = new MouseEvent("click", { | |
view: window, | |
bubbles: true, | |
cancelable: true, | |
}); | |
element.dispatchEvent(event); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Link from "next/link"; | |
export default function NotFound() { | |
return ( | |
<main className="grid place-items-center p-5 min-h-screen w-full bg-gradient-to-r from-purple-200 to-purple-500 "> | |
<section className="relative grid gap-3 rounded shadow-lg p-5 lg:p-10 xl:px-20 bg-purple-200"> | |
<h1 className="text-center text-purple-700 font-bold text-8xl lg:text-9xl 2xl:text-[15rem]">404</h1> | |
<p className="text-purple-900 text-base lg:text-xl xl:text-2xl mb-5"> | |
Oops! The page you are looking for does not exist. It might have been moved or deleted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from "next/server"; | |
import { AxiosInstance } from "axios"; | |
import { CookieKeys } from "@/_enums"; | |
import createAuthenticatedApiServiceV2 from "@/_services/createAuthenticatedApiServiceV2"; | |
import handleAxiosError from "@/_utilities/handleAxiosError"; | |
export async function GET(request: NextRequest) { | |
try { | |
const jwt: string | undefined = request.cookies.get(CookieKeys.Jwt)?.value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeEvent, useCallback, useEffect, useState } from "react"; | |
import { CiSearch } from "react-icons/ci" | |
import { useSearch } from "@/store/useSearch"; | |
const Search = () => { | |
const [ searchText, setSearchText ] = useState(""); | |
const setSearch = useSearch(state => state.setSearch); | |
const [ debouncedSearchText, setDebouncedSearchText ] = useState(searchText); | |
const handleSearchText = useCallback((event: ChangeEvent<HTMLInputElement>) => { | |
const value = event.target.value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FieldError } from 'react-hook-form'; | |
import { ChangeEvent } from "react"; | |
interface Props { | |
label: string; | |
id: string; | |
type?: string; | |
placeholder?: string; | |
disabled?: boolean; | |
register?: any; |