Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tubbo/jest-ejs-transformer
Use EJS templates in your Jest tests
https://github.com/tubbo/jest-ejs-transformer
ejs javascript jest
Last synced: about 1 month ago
JSON representation
Use EJS templates in your Jest tests
- Host: GitHub
- URL: https://github.com/tubbo/jest-ejs-transformer
- Owner: tubbo
- Created: 2020-07-05T22:58:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:14:55.000Z (about 1 year ago)
- Last Synced: 2024-05-21T12:29:54.290Z (8 months ago)
- Topics: ejs, javascript, jest
- Language: JavaScript
- Homepage:
- Size: 1.17 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jest-ejs-transformer
Use [EJS](https://ejs.co/) templates in your [Jest](https://jestjs.io/) tests.
## Installation
yarn add jst-ejs-transformer
## Usage
In your **jest.config.js**:
```javascript
const { defaults: { moduleFileExtensions } } = require("jest-config")module.exports = {
moduleFileExtensions: [ ...moduleFileExtensions, "ejs"],
transform: {
"\\.ejs$": "jest-ejs-transformer",
//"\\.js$": "babel-jest" (optional)
}
}
```You can now `import` or `require` an EJS template as a module:
```javascript
const Template = require("./template/ejs")module.exports = {
render(props) {
return Template(props)
}
}
```## Thanks!
Special thanks to **Matt Rose** and **Roman Loktev** for the code behind
this package. I just copied their code from [StackOverflow](https://stackoverflow.com/questions/44220227/jest-testing-with-require-modules-ejs-loader)
and put it in a reusable module.