X Tutup
The Wayback Machine - https://web.archive.org/web/20201104075044/https://github.com/formium/tsdx/issues/414
Skip to content
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

Additional Jest config to stub static assets and stylesheets #414

Open
edwardpayton opened this issue Jan 4, 2020 · 2 comments
Open

Additional Jest config to stub static assets and stylesheets #414

edwardpayton opened this issue Jan 4, 2020 · 2 comments

Comments

@edwardpayton
Copy link

@edwardpayton edwardpayton commented Jan 4, 2020

Current Behavior

For every new project I start with TSDX, one of my first steps is to add stubs for static assets and stylesheets - as detailed on the Jest docs.

Desired Behavior

Add Jest file stubs in to the TSDX setup.

Suggested Solution

Following the Jest docs

// package.json
{
  "jest": {
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
      "\\.(css|less)$": "identity-obj-proxy"
    }
  }
}
// test/__mocks__/fileMock.js
module.exports = 'test-file-stub';

yarn add --dev identity-obj-proxy

This prevents images and stylesheets causing errors while testing. These steps have been sufficient in any of my use cases.

Who does this impact? Who is this for?

Css modules and / or images are not recognised by Jest so cause errors. So this is for anybody who writes tests with their components.

It will help prevent beginners being confused by console errors that they may not find clear, and advanced users who go through the same setup on each project they work on.

Describe alternatives you've considered

I'm not searching for alternatives applies here.

Additional context

I can work on this and submit a Pull Request when done. That was going to be my first action but thought opening an issue here may invite others ideas.

Also, fantastic library! My favourite TypeScript setup, I use it any chance I find.

All the best
Ed

@jaredpalmer
Copy link
Member

@jaredpalmer jaredpalmer commented Jan 4, 2020

Can likely steal from CRA’s setup

@edwardpayton
Copy link
Author

@edwardpayton edwardpayton commented Jan 5, 2020

Good idea, I'll take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
X Tutup