No tests found, When rename *.ts to *.spec.ts for component testing
See original GitHub issueCurrent behavior
- Create any
*.tsx
or*.ts
file insrc
- Write any content in that new file and save it
- Rename that file to
*.spec.tsx
or*.spec.ts
- Write proper test code in that file like below and save it
import { mount } from "@cypress/react";
import App from "./App";
describe("App", () => {
it("test", () => {
mount(<App />);
expect(true).to.eq(true);
});
});
- Run unit test by scripts
cypress open-ct
- Then we can see “No tests found” for new file
- Tests cannot be found for all
*.spec.ts
files created afterwards. In order to solve it, I couldn’t find any solution except for erasingnode_modules
. This phenomenon does not occur inside the cypress/integration folder. It occurs only for component unit tests.
Desired behavior
Now that I know this phenomenon, there is no problem if I work carefully. Though, I report because the difference that this phenomenon does not occur in the cypress/integration folder.
Test code to reproduce
- cypress.json
{
"testFiles": "**/*.spec.ts",
"component": {
"componentFolder": "src",
"testFiles": ["**/*.spec.tsx", "**/*.spec.ts"]
}
}
- plugins/index.js
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
if (config.testingType === "component") {
require("@cypress/react/plugins/react-scripts")(on, config);
}
return config;
};
- package.json
{
"dependencies": {
"@types/node": "^17.0.8",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^5.0.0",
"typescript": "^4.5.4",
"web-vitals": "^2.1.3"
},
"devDependencies": {
"@cypress/react": "^5.12.0",
"@cypress/webpack-dev-server": "^1.8.0",
"@typescript-eslint/parser": "^5.9.0",
"cypress": "^9.2.1",
"postcss-normalize": "^10.0.1"
}
}
I made a repo for you to see code https://github.com/cocoder16/cypress-issue-report-no-tests-found
Cypress Version
9.2.1
Other
Code editor: vscode OS: windows
I love this framework and thank you for making this 🥰
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to test a specific spec.ts file in Angular 4? - Stack Overflow
First go to the component into the spec.ts file of the component. then put f in ... Then go to console or terminal...
Read more >Testing - ts - GUIDE - Angular
Open the 1st.spec.ts test file (Control/Command-P, then start typing the name of the file). ... src/app/banner-inline.component.spec.ts (no detectChanges).
Read more >Writing and Organizing Tests - Cypress Documentation
Spec files. Test files are located in cypress/e2e by default, but can be configured to another directory. Test files may be written as:...
Read more >Angular 7 + unit testing + code coverage | by Manivel Arjunan
Open the app.component.spec.ts test file (Control/Command-P, then start typing the name of ... Pipes are easy to test without the Angular testing utilities....
Read more >Wow! Cypress can run unit tests! - DEV Community
cypress folder and rename the spec files from .js to .ts; import your library (or whatever software you're testing) at the top of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lmiller1990 we are good, I’ll update the PR today so we can get it merged.
Yep - the problem must be that the dev server doesn’t pick up new files (renaming is kind of like making a new file).
This is actually a duplicate of https://github.com/cypress-io/cypress/issues/16664 which has an open fix: https://github.com/cypress-io/cypress/pull/17950
@ZachJW34 are we good to merge that fix you did?