1+ import { isMatch } from "lodash" ;
12import createClient from "openapi-fetch" ;
23import * as React from "react" ;
34import * as SWR from "swr" ;
45import type { ScopedMutator } from "swr/_internal" ;
56import { afterEach , describe , expect , it , vi } from "vitest" ;
67import { createMutateHook } from "../mutate.js" ;
78import type { paths } from "./fixtures/petstore.js" ;
8- import { isMatch } from "lodash" ;
99
1010// Mock `useCallback` (return given function as-is)
1111vi . mock ( "react" ) ;
@@ -44,10 +44,7 @@ describe("createMutateHook", () => {
4444 it ( "returns callback that invokes swr `mutate` with fn, data and options" , async ( ) => {
4545 expect ( swrMutate ) . not . toHaveBeenCalled ( ) ;
4646
47- const data = {
48- name : "doggie" ,
49- photoUrls : [ "https://example.com" ] ,
50- } ;
47+ const data = [ { name : "doggie" , photoUrls : [ "https://example.com" ] } ] ;
5148 const config = { throwOnError : false } ;
5249
5350 await mutate ( [ "/pet/findByStatus" ] , data , config ) ;
@@ -65,7 +62,7 @@ describe("createMutateHook", () => {
6562
6663 describe ( "useMutate -> mutate -> key matcher" , ( ) => {
6764 it ( "returns false for non-array keys" , async ( ) => {
68- await mutate ( [ "/pet/findByTags " ] ) ;
65+ await mutate ( [ "/pet/findByStatus " ] ) ;
6966 const keyMatcher = getKeyMatcher ( ) ;
7067
7168 expect ( keyMatcher ( null ) ) . toBe ( false ) ;
@@ -75,7 +72,7 @@ describe("createMutateHook", () => {
7572 } ) ;
7673
7774 it ( "returns false for arrays with length !== 3" , async ( ) => {
78- await mutate ( [ "/pet/findByTags " ] ) ;
75+ await mutate ( [ "/pet/findByStatus " ] ) ;
7976 const keyMatcher = getKeyMatcher ( ) ;
8077
8178 expect ( keyMatcher ( Array ( 0 ) ) ) . toBe ( false ) ;
@@ -86,19 +83,19 @@ describe("createMutateHook", () => {
8683 } ) ;
8784
8885 it ( "matches when prefix and path are equal and init isn't given" , async ( ) => {
89- await mutate ( [ "/pet/findByTags " ] ) ;
86+ await mutate ( [ "/pet/findByStatus " ] ) ;
9087 const keyMatcher = getKeyMatcher ( ) ;
9188
9289 // Same path, no init
93- expect ( keyMatcher ( [ "<unique-key>" , "/pet/findByTags " ] ) ) . toBe ( true ) ;
90+ expect ( keyMatcher ( [ "<unique-key>" , "/pet/findByStatus " ] ) ) . toBe ( true ) ;
9491
9592 // Same path, init ignored
9693 expect (
97- keyMatcher ( [ "<unique-key>" , "/pet/findByTags " , { some : "init" } ] ) ,
94+ keyMatcher ( [ "<unique-key>" , "/pet/findByStatus " , { some : "init" } ] ) ,
9895 ) . toBe ( true ) ;
9996
10097 // Same path, undefined init ignored
101- expect ( keyMatcher ( [ "<unique-key>" , "/pet/findByTags " , undefined ] ) ) . toBe (
98+ expect ( keyMatcher ( [ "<unique-key>" , "/pet/findByStatus " , undefined ] ) ) . toBe (
10299 true ,
103100 ) ;
104101 } ) ;
@@ -107,7 +104,7 @@ describe("createMutateHook", () => {
107104 const psudeoCompare = vi . fn ( ) . mockReturnValue ( "booleanPlaceholder" ) ;
108105
109106 const prefix = "<unique-key>" ;
110- const path = "/pet/findByTags " ;
107+ const path = "/pet/findByStatus " ;
111108 const givenInit = { } ;
112109
113110 const useMutate = createMutateHook ( client , prefix , psudeoCompare ) ;
0 commit comments