Skip to content

Commit

Permalink
Merge pull request #16 from b3hniya/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
b3hniya authored Dec 13, 2023
2 parents 280fdd9 + e566f67 commit 1199f19
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/hooks/useCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ export function useCaller<DATA_TYPE extends unknown = any, RESPONSE_TYPE extends
if (apiCallOptions.makeInitialCall || apiCallOptions.dependencies) call()
}, apiCallOptions.dependencies ?? [])

return { data, error, loading, axiosInstance, easyCallConfig, call }
return { data, error, loading, axiosInstance, easyCallConfig, call, setError }
}
2 changes: 1 addition & 1 deletion lib/hooks/useGetCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const useGetCaller = (callerName: string) => {
const { callers } = useContext(CallerContext)

return {
caller: callers[callerName],
call: callers[callerName],
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easycall",
"version": "0.0.55",
"version": "0.0.56",
"description": "easyapi, is a framework to call api and store results painlessly.",
"keywords": [
"easycall",
Expand Down Expand Up @@ -41,6 +41,7 @@
"typescript": "^5.1.6"
},
"volta": {
"node": "18.17.1"
"node": "18.17.1",
"yarn": "1.22.19"
}
}
9 changes: 3 additions & 6 deletions test/createApiMethod.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createCaller } from "../lib/helper/createCaller.helper"

describe("creates api methods", () => {

it("it creates api methods based on given endpoints", async () => {
// ARRANGE
const { callers } = createCaller({
Expand All @@ -12,12 +11,10 @@ describe("creates api methods", () => {
key: "todo",
method: "get",
endpoint: "todo",
}
]
},
],
})

const data = await callers?.todo?.get?.()
console.log(data)
})

})
})
33 changes: 33 additions & 0 deletions test/useGetCaller.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react"
import { useGetCaller } from "../lib"

describe("useGetCaller", () => {
it("should return the correct caller when a valid caller name is provided", () => {
const callerName = "testCaller"
const mockCall = jest.fn()
const mockContext = {
callers: {
[callerName]: mockCall,
},
}

jest.spyOn(React, "useContext").mockReturnValue(mockContext)

const { call } = useGetCaller(callerName)

expect(call).toBe(mockCall)
})

it("should return undefined when an invalid caller name is provided", () => {
const callerName = "invalidCaller"
const mockContext = {
callers: {},
}

jest.spyOn(React, "useContext").mockReturnValue(mockContext)

const { call } = useGetCaller(callerName)

expect(call).toBeUndefined()
})
})
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es5",
"lib": ["es6", "dom"],
"target": "ES2018",
"lib": ["ES2018", "dom"],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
Expand Down

0 comments on commit 1199f19

Please sign in to comment.