-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
[legacy-framework] Fix typescript jest issue in forgotPassword.test.ts
#2110
Changes from 6 commits
a651c0b
55c6afa
6399d86
db307ca
71285b5
cd2bdca
8ea14c9
88de5c5
321e963
2e17e47
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {hash256, Ctx} from "blitz" | ||
import { hash256, Ctx } from "blitz" | ||
import forgotPassword from "./forgotPassword" | ||
import db from "db" | ||
import previewEmail from "preview-email" | ||
|
@@ -8,15 +8,15 @@ beforeEach(async () => { | |
}) | ||
|
||
const generatedToken = "plain-token" | ||
jest.mock("@blitzjs/core/server", () => ({ | ||
...jest.requireActual("@blitzjs/core/server")!, | ||
jest.mock("blitz", () => ({ | ||
...jest.requireActual<object>("blitz")!, | ||
generateToken: () => generatedToken, | ||
})) | ||
jest.mock("preview-email", () => jest.fn()) | ||
|
||
describe("forgotPassword mutation", () => { | ||
it("does not throw error if user doesn't exist", async () => { | ||
await expect(forgotPassword({email: "[email protected]"}, {} as Ctx)).resolves.not.toThrow() | ||
await expect(forgotPassword({ email: "[email protected]" }, {} as Ctx)).resolves.not.toThrow() | ||
}) | ||
|
||
it("works correctly", async () => { | ||
|
@@ -34,13 +34,13 @@ describe("forgotPassword mutation", () => { | |
}, | ||
}, | ||
}, | ||
include: {tokens: true}, | ||
include: { tokens: true }, | ||
}) | ||
|
||
// Invoke the mutation | ||
await forgotPassword({email: user.email}, {} as Ctx) | ||
await forgotPassword({ email: user.email }, {} as Ctx) | ||
|
||
const tokens = await db.token.findMany({where: {userId: user.id}}) | ||
const tokens = await db.token.findMany({ where: { userId: user.id } }) | ||
const token = tokens[0] | ||
|
||
// delete's existing tokens | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import {render} from "test/utils" | ||
import { render } from "test/utils" | ||
|
||
import Home from "./index" | ||
import { useCurrentUser } from "app/core/hooks/useCurrentUser" | ||
|
||
jest.mock("@blitzjs/core", () => ({ | ||
...jest.requireActual("@blitzjs/core")!, | ||
useQuery: () => [ | ||
{ | ||
id: 1, | ||
name: "User", | ||
email: "[email protected]", | ||
role: "user", | ||
}, | ||
], | ||
})) | ||
jest.mock("app/core/hooks/useCurrentUser") | ||
const mockUseCurrentUser = useCurrentUser as jest.MockedFunction<typeof useCurrentUser> | ||
|
||
test("renders blitz documentation link", () => { | ||
// This is an example of how to ensure a specific item is in the document | ||
// But it's disabled by default (by test.skip) so the test doesn't fail | ||
// when you remove the the default content from the page | ||
|
||
// This is an example on how to mock api hooks when testing | ||
mockUseCurrentUser.mockReturnValue({ | ||
id: 1, | ||
name: "User", | ||
email: "[email protected]", | ||
role: "user", | ||
}) | ||
|
||
const {getByText} = render(<Home />) | ||
const element = getByText(/powered by blitz/i) | ||
// @ts-ignore | ||
expect(element).toBeInTheDocument() | ||
const { getByText } = render(<Home />) | ||
const linkElement = getByText(/Documentation/i) | ||
expect(linkElement).toBeInTheDocument() | ||
}) | ||
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. So some change in this file is still causing tests to fail. Not sure if 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. Ah I see. Should the test syncing be a separate PR then? I can commit just the single change to satisfy typescript and we can update the auth tests later? 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. it's up to you. If we get tests passing, then fine to keep the change here. CI auto runs on each 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. Ah, I see. I reverted back to the original tests, with the only change being the 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. Ok, that was on me, I forgot to push the changes I'd made after resolving a merge conflict, I reran the yarn jest command and eslint --fix and lint, and those passed and waiting for the results of the CI tests |
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.
Thanks @roesh!
You have to actually revert this change as it breaks example tests here in the monorepo. Maybe a way to fix it, but needs to be
@blitzjs/core/server
for nowThere 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.
Ah, got it. Let me revert that