-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Harley Alexander
committed
Mar 3, 2020
1 parent
489ed35
commit a301670
Showing
9 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
collectCoverageFrom: ["src/**/*.{ts,tsx}"], | ||
coveragePathIgnorePatterns: ["./src/index.ts"], | ||
modulePathIgnorePatterns: ["./src/__oldtests__/"] | ||
coveragePathIgnorePatterns: ["./src/index.ts"] | ||
}; |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import "jest-fetch-mock"; | ||
|
||
import { NO_AUTH_HEADERS_WARNING, useTrigger } from "../useTrigger"; | ||
|
||
import Pusher from "pusher-js"; | ||
import { PusherMock } from "pusher-js-mock"; | ||
import React from "react"; | ||
import { __PusherContext } from "../PusherProvider"; | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
|
||
describe("useTrigger()", () => { | ||
beforeEach(() => { | ||
fetch.resetMocks(); | ||
}); | ||
test("should trigger a fetch event on use and warn about no headers", async () => { | ||
jest.spyOn(console, "warn"); | ||
const wrapper = ({ children }) => ( | ||
<__PusherContext.Provider | ||
value={{ | ||
client: (new PusherMock("key") as unknown) as Pusher, | ||
triggerEndpoint: "http://example.com" | ||
}} | ||
> | ||
{children} | ||
</__PusherContext.Provider> | ||
); | ||
|
||
const { result } = await renderHook(() => useTrigger("presence-channel"), { | ||
wrapper | ||
}); | ||
|
||
result.current("event", {}); | ||
expect(fetch.mock.calls.length).toBe(1); | ||
expect(console.warn).toHaveBeenCalledWith(NO_AUTH_HEADERS_WARNING); | ||
}); | ||
test("should trigger a fetch event on use and warn", async () => { | ||
jest.spyOn(console, "warn"); | ||
const config = { | ||
auth: { | ||
headers: "Bearer token" | ||
} | ||
}; | ||
|
||
const wrapper = ({ children }) => ( | ||
<__PusherContext.Provider | ||
value={{ | ||
client: (new PusherMock("key", { | ||
auth: { | ||
headers: { | ||
Authorization: "Bearer token" | ||
} | ||
} | ||
}) as unknown) as Pusher, | ||
triggerEndpoint: "http://example.com" | ||
}} | ||
> | ||
{children} | ||
</__PusherContext.Provider> | ||
); | ||
|
||
const { result } = await renderHook(() => useTrigger("public-channel"), { | ||
wrapper | ||
}); | ||
|
||
result.current("event", {}); | ||
expect(fetch.mock.calls[0]).toEqual([ | ||
"http://example.com", | ||
{ | ||
method: "POST", | ||
body: JSON.stringify({ | ||
channelName: "public-channel", | ||
eventName: "event", | ||
data: {} | ||
}), | ||
headers: { | ||
Authorization: "Bearer token" | ||
} | ||
} | ||
]); | ||
}); | ||
}); |
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 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 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 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 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