Giter Site home page Giter Site logo

Comments (7)

andrewconnell avatar andrewconnell commented on July 1, 2024

What are the actual suites (files) named? Can you share an example of your full path?

This should work for the following:

  • /tests/something.spec.tsx
  • /tests/folder/something.spec.tsx
  • either of the above with "test" instead of "spec" in the name
  • either of the above for JSX files
  • either of the above with additional nested folders

from jest-preset-spfx-react16.

juliemturner avatar juliemturner commented on July 1, 2024

yes, so an actual example file is:
/tests/common/services/UpgradeServices.spec.ts

The provided jest-preset.json file specifies the following
"testMatch": [ "**/src/**/*.(spec|test).+(ts|js)?(x)", "**/__tests__/**/*.(spec|test).+(ts|js)?(x)" ],
That setup will not find my above file on windows. However, if I adjust it to the following it works fine:
"testMatch": [ "**/src/**/*.(spec|test).+(ts|js)?(x)", "**/tests/**/*.(spec|test).+(ts|js)?(x)", "**/__tests__/**/*.(spec|test).+(ts|js)?(x)" ],
I was basically trying to verify that my assumption that __tests__ was indeed a pattern that should match the root folder tests as a sibling of src. What I'm wondering is if this is a limitation of mac vs windows.

from jest-preset-spfx-react16.

andrewconnell avatar andrewconnell commented on July 1, 2024

It's not finding it because your folder is named tests, not __tests__

from jest-preset-spfx-react16.

juliemturner avatar juliemturner commented on July 1, 2024

Actually, I tried that first, thinking it was literal and not a pattern and that doesn't work. I just retested it again to make sure, also copied the value __tests__ to make sure there is no encoding problem as I've had that bite me with PowerShell.

To to be clear this path also doesn't work:
__tests__/common/services/UpgradeServices.spec.ts

from jest-preset-spfx-react16.

juliemturner avatar juliemturner commented on July 1, 2024

My current workaround, that's good for anyone else to know in case they have a requirement that their tests be in some folder way outside the patterns you support, is to add an entry into the jest.config.json file in the config folder... so this:

{
"preset": "@voitanos/jest-preset-spfx-react16",
"rootDir": "../tests",
"testMatch": [
"**/tests/**/*.(spec|test).+(ts|js)?(x)"
]
}

from jest-preset-spfx-react16.

andrewconnell avatar andrewconnell commented on July 1, 2024

_ isn't a special character in regex... just a string.

Most developers when writing tests put them either beside the code they test (ie: src) or in a __tests__ folder as that pattern matches the folders generated by snapshots when doing React component rendering tests.

If you want to have your tests in a folder separate from your source, just override the testMatch property defined in the preset. If you wanted it to be either "src" or "tests", set the contents of jest.config.json to:

{
  "preset": "@voitanos/jest-preset-spfx-react16",
  "rootDir": "../tests",
  "testMatch": [
    "**/(src|tests)/**/*.(spec|test).+(ts|js)?(x)"
  ]
}

from jest-preset-spfx-react16.

juliemturner avatar juliemturner commented on July 1, 2024

Yep, well... for whatever reason I can't use the folder __tests__ so... it's what it is... and I had applied the workaround... thanks for the confirmation.

from jest-preset-spfx-react16.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.