File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 1- import * as vue from "vue-demi" ;
1+ import { inject } from "vue-demi" ;
22import { useQueryClient , VUE_REACT_QUERY_CLIENT } from "../src/useQueryClient" ;
33
4+ jest . mock ( "vue-demi" , ( ) => {
5+ const vue = jest . requireActual ( "vue-demi" ) ;
6+ return {
7+ ...vue ,
8+ inject : jest . fn ( ) ,
9+ } ;
10+ } ) ;
11+
412describe ( "useQueryClient" , ( ) => {
13+ const injectSpy = inject as jest . Mock ;
14+
515 beforeEach ( ( ) => {
616 jest . restoreAllMocks ( ) ;
17+ jest . clearAllMocks ( ) ;
718 } ) ;
819
920 test ( "should return queryClient when it is provided in the context" , ( ) => {
1021 const queryClientMock = { name : "Mocked client" } ;
11- const injectSpy = jest
12- . spyOn ( vue , "inject" )
13- . mockReturnValue ( queryClientMock ) ;
22+ injectSpy . mockReturnValueOnce ( queryClientMock ) ;
1423
1524 const queryClient = useQueryClient ( ) ;
1625
@@ -20,7 +29,7 @@ describe("useQueryClient", () => {
2029 } ) ;
2130
2231 test ( "should throw an error when queryClient does not exist in the context" , ( ) => {
23- const injectSpy = jest . spyOn ( vue , "inject" ) . mockReturnValue ( undefined ) ;
32+ injectSpy . mockReturnValueOnce ( undefined ) ;
2433
2534 expect ( useQueryClient ) . toThrowError (
2635 Error (
You can’t perform that action at this time.
0 commit comments