-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useUser custom hook 사용 #126
Changes from 5 commits
abdc7b4
80a7f20
d5deb3b
fb8a8ef
bc1b980
42c4a3b
d94fe99
2fe03ab
5271149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,14 +5,16 @@ import { fireAntEvent } from "../setupTests"; | |||
|
||||
describe("Test", () => { | ||||
test("Sign In", async () => { | ||||
const fakeUser = {} as firebase.User; | ||||
((firebase.auth as unknown) as jest.Mock).mockReturnValue({ | ||||
currentUser: null, | ||||
onAuthStateChanged: jest.fn(), | ||||
onAuthStateChanged: (callback: (user: firebase.User | null) => void) => { | ||||
callback(null); | ||||
}, | ||||
signInWithPhoneNumber: jest.fn().mockResolvedValue({ | ||||
confirm: jest.fn().mockResolvedValue({ | ||||
additionalUserInfo: { isNewUser: false }, | ||||
user: {}, | ||||
}), | ||||
confirm: jest.fn().mockImplementation((callback: (user: firebase.User | null) => void) => { | ||||
callback(fakeUser); | ||||
}) | ||||
}), | ||||
}); | ||||
((firebase.firestore as unknown) as jest.Mock).mockReturnValue({ | ||||
|
@@ -42,10 +44,13 @@ describe("Test", () => { | |||
}); | ||||
|
||||
test("Sign Out", async () => { | ||||
const fakeUser = null; | ||||
((firebase.auth as unknown) as jest.Mock).mockReturnValue({ | ||||
onAuthStateChanged: jest.fn(), | ||||
currentUser: {}, | ||||
signOut: jest.fn().mockResolvedValue(null), | ||||
signOut: jest.fn().mockImplementation((callback: (user: firebase.User | null) => void) => { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header코드 보면 signOut을 입력값 하나도 안 넘겨. dailyfield/src/components/Header.tsx Line 79 in 5bd5517
그래서 이 목이 callback안 받을거야. 그래서 오류 날거야. 이 코드 같아: function mockSignOut(callback) {
callback(null);
}
mockSignOut(); 돌리면 callback이 undefined이야. 그래서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 await firebase.auth().signOut(); 이부분은 이해했어! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응! 만날때 보여줄게 |
||||
callback(null); | ||||
}), | ||||
}); | ||||
|
||||
render(<Header />); | ||||
|
@@ -57,6 +62,7 @@ describe("Test", () => { | |||
test("Sign In Status", async () => { | ||||
const fakeUser = {} as firebase.User; | ||||
((firebase.auth as unknown) as jest.Mock).mockReturnValue({ | ||||
currentUser: {}, | ||||
onAuthStateChanged: (callback: (user: firebase.User) => void) => { | ||||
callback(fakeUser); | ||||
}, | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useState, useEffect } from "react"; | ||
import firebase from "firebase"; | ||
|
||
export function useUser(): firebase.User | null { | ||
const [user, setUser] = useState(firebase.auth().currentUser); | ||
|
||
useEffect(() => { | ||
firebase.auth().onAuthStateChanged(setUser); | ||
}, []); | ||
|
||
return user; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떻게 confirm돌리는지 보면 callback아니라 code 남겨:
dailyfield/src/components/Header.tsx
Line 58 in 5bd5517
그래서 이런 목 만들면 안 될거야.