question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No tests found, When rename *.ts to *.spec.ts for component testing

See original GitHub issue

Current behavior

  1. Create any *.tsx or *.ts file in src
  2. Write any content in that new file and save it
  3. Rename that file to *.spec.tsx or *.spec.ts
  4. 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);
  });
});
  1. Run unit test by scripts cypress open-ct
  2. Then we can see “No tests found” for new file failed pic
  3. Tests cannot be found for all *.spec.ts files created afterwards. In order to solve it, I couldn’t find any solution except for erasing node_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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ZachJW34commented, Jan 19, 2022

@lmiller1990 we are good, I’ll update the PR today so we can get it merged.

1reaction
lmiller1990commented, Jan 19, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found