ilearnio / module-alias

Register aliases of directories and custom module paths in Node
MIT License
1.76k stars 69 forks source link

Incrementing README.md with Jest usage. #77

Closed diogocezar closed 5 years ago

diogocezar commented 5 years ago

Just inserted new section explaining how we can use this package with Jest.

diogocezar commented 5 years ago

For me, sounds good ;)

On 21 Nov 2019 17:33 -0300, Nick Gavrilov notifications@github.com, wrote:

@ilearnio requested changes on this pull request. Thanks for contributing! It's was definitely a missing piece of documentation. Just adjusted the description a little. If you think it's good, hit "commit suggestion" and we can merge In README.md:

@@ -143,6 +143,21 @@ module.exports = {

}


+## Usage with Jest

+

+If you use jest to test your application, you can structure this kind of configuration to run tests:

⬇️ Suggested change
-If you use jest to test your application, you can structure this kind of configuration to run tests:

+Unfortunately, `module-alias` itself would not work from Jest due to a custom behavior of Jest's `require`. But you can use it's own aliasing mechanism instead. The configuration can be defined either in `package.json` or `jest.config.js`. The example below is for `package.json`:

In README.md:
> @@ -143,6 +143,21 @@ module.exports = {

}

+## Usage with Jest

+

+If you use jest to test your application, you can structure this kind of configuration to run tests:

+

+```js

+"jest": {

  • "moduleNameMapper": {

  • "@root/(.*)": "/$1",

  • "@client/(.*)": "/src/client/$1"

  • },

+}

+```

+

+Just put it on package.json or in yout jest.config.js

⬇️ Suggested change -Just put it on package.json or in yout jest.config.js

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ilearnio commented 5 years ago

Thank you! Merging it