The default test in my new Blitz app isn't getting found.
In a new Blitz app, edit index.test.tsx file, changing test.skip to test:
import React from "react"
import { render } from "test/utils"
import Home from "./index"
import { useCurrentUser } from "app/hooks/useCurrentUser"
jest.mock("app/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 linkElement = getByText(/Documentation/i)
expect(linkElement).toBeInTheDocument()
})
debug: blitzPkgPath: /Users/dan/dev/blitz/lingovert-blitz/node_modules/blitz/dist/index.js
debug: cliPkgPath: /Users/dan/dev/blitz/lingovert-blitz/node_modules/@blitzjs/cli/lib/src/index.js
macOS High Sierra | darwin-x64 | Node: v14.8.0
blitz: 0.24.1 (global)
blitz: 0.24.1 (local)
Package manager: yarn
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
Memory: 802.26 MB / 8.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 14.8.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.7 - /usr/local/bin/npm
Watchman: Not Found
npmPackages:
@prisma/cli: 2.8.1 => 2.8.1
@prisma/client: 2.8.1 => 2.8.1
blitz: 0.24.1 => 0.24.1
react: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8
react-dom: 0.0.0-experimental-7f28234f8 => 0.0.0-experimental-7f28234f8
typescript: 4.0.3 => 4.0.3
Terminal (iTerm2, zsh, oh-my-zsh) output when I try to run the tests:
\w $ blitz test
You are using alpha software - if you have any problems, please open an issue here:
https://github.com/blitz-js/blitz/issues/new/choose
yarn run v1.22.4
$ jest
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
No files found in /Users/dan/dev/blitz/lingovert-blitz.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Pattern: - 0 matches
error Command failed with exit code 1.
Here's the jest config template for whoever wants to work on this.
I'm happy to look into this issue, in the first setup we've worked on it was working just fine I think.
Here's the jest config template for whoever wants to work on this.
In the meantime I found you can get the tests picked up by passing --runTestsByPath to the jest command:
"test": "jest --runTestsByPath app/**/*.test.ts*"
Interesting, I am unable to reproduce the issue. @danielrlc @shaunchurch could you provide more information about your setup?
I just bootstrapped a new app with blitz then ran the test, and it actually raised an error, but it was able to find the test to run. The output:
blitz test
You are using alpha software - if you have any problems, please open an issue here:
https://github.com/blitz-js/blitz/issues/new/choose
yarn run v1.22.0
$ jest
FAIL app/pages/index.test.tsx
✕ renders blitz documentation link (74 ms)
● renders blitz documentation link
It looks like you are trying to use Blitz's useQuery to fetch from third-party APIs. To do that, import useQuery directly from "react-query"
12 | const UserInfo = () => {
13 | const currentUser = useCurrentUser()
> 14 | const [logoutMutation] = useMutation(logout)
| ^
15 |
16 | if (currentUser) {
17 | return (
at validateQueryFn (node_modules/@blitzjs/core/src/utils/react-query-utils.ts:57:11)
at UserInfo (app/pages/index.tsx:14:28)
at render (test/utils.tsx:37:10)
at Object.<anonymous> (app/pages/index.test.tsx:23:25)
console.error
Error: Uncaught [Error: It looks like you are trying to use Blitz's useQuery to fetch from third-party APIs. To do that, import useQuery directly from "react-query"]
...
@peaonunes Thanks for looking into this. It looks like this was fixed in the latest release (https://github.com/blitz-js/blitz/pull/1323). Can confirm a recently bootstrapped project works just fine now, skipping the skipped test as expected. 👍
I still had this issue, and got it fixed in #1355
The newapp jest config had modulePathIgnorePatterns: [".blitz"] to ignore the blitz build directory, but this is a regex and so if the project name had "blitz" in it, then all tests in the project would be ignored.
Most helpful comment
In the meantime I found you can get the tests picked up by passing
--runTestsByPathto the jest command:"test": "jest --runTestsByPath app/**/*.test.ts*"