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 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
interface User { | |
_id: string; | |
name: string; | |
} | |
interface State { | |
users: User[]; | |
addUser: (user: User) => void; |
This file contains 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 { lazy, Suspense, useEffect } from "react"; | |
import useModalStore from "@/hooks/useModalStore.ts"; | |
const Modal = lazy(() => import("@/components/Modal.tsx")) | |
function Loading() { | |
return <h2>🌀 Loading...</h2>; | |
} | |
function App() { |
This file contains 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
/** | |
* This Gist demonstrates a simple yet effective implementation of a memoization function in JavaScript. | |
* Memoization is an optimization technique used to speed up computer programs by storing the results of expensive function | |
* calls and returning the cached result when the same inputs occur again. | |
*/ | |
const memoMap = new Map(); | |
const complexFunction = (a1: number[], a2: number[]): number => { | |
// Simulate heavy calculations |
This file contains 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
<template> | |
<div class="app"> | |
<button @click="store.mutations.open()">Open Modal </button> | |
<Modal v-if="store.state.isModalOpen"/> | |
</div> | |
</template> | |
<script setup> | |
import store from "./store"; | |
import Modal from "./Modal.vue"; |
This file contains 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
<template> | |
<div class="app"> | |
<button @click="store.mutations.open()">Open Modal </button> | |
<Modal v-if="store.state.isModalOpen"/> | |
</div> | |
</template> | |
<script setup> | |
import store from "./store"; | |
import Modal from "./Modal.vue"; |
This file contains 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 { createStore } from "vuex"; | |
import type { Post } from "@/types"; | |
export interface ApisLoadState { | |
isCalled: boolean; | |
isLoaded: boolean; | |
} | |
export interface ApiLoadState extends ApisLoadState { | |
api: string; |
This file contains 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
declare global { | |
interface AmplitudeInstance { | |
logEvent(eventName: string, eventProperties?: object): void; | |
identify(identifyObject: object): void; | |
setUserId(userId: string | null): void; | |
init(apiKey: string, userId?: string, options?: object, callback?: () => void): void; | |
} | |
interface Amplitude { | |
getInstance(): AmplitudeInstance; |
This file contains 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 { expect, describe, it, beforeAll, afterEach, afterAll, beforeEach } from "vitest"; | |
import { QueryClientProvider } from "react-query"; | |
import { ReactNode } from "react"; | |
import { http, HttpResponse } from "msw"; | |
import { useCommonStore } from "@/_store/useCommonStore"; | |
import { act, renderHook, waitFor } from "@testing-library/react"; | |
import { createTestServer, queryClient } from "@/__tests__/utilities"; | |
import useFetchCustomVariables from "@/_hooks/useFetchCustomVariables"; | |
const successResponse = [ |
This file contains 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 } from "vitest"; | |
import { renderHook } from "@testing-library/react"; | |
import useDeepCompareMemoize from "./useDeepCompareMemoize"; | |
describe("useDeepCompareMemoize", () => { | |
it('should return a memoized version of the input value based on deep comparison', () => { | |
const initialData = { user: { name: 'John', age: 25, city: 'New York' } }; | |
const newData = { user: { name: 'Alice', age: 30, city: 'San Francisco' } }; | |
const identicalData = { user: { name: 'John', age: 25, city: 'New York' } }; |
NewerOlder