tubbo / jest-ejs-transformer

Use EJS templates in your Jest tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jest-ejs-transformer

Use EJS templates in your Jest tests.

Installation

yarn add jst-ejs-transformer

Usage

In your jest.config.js:

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:

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 and put it in a reusable module.

About

Use EJS templates in your Jest tests


Languages

Language:JavaScript 96.4%Language:HTML 3.6%