Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 1.36 KB

README.md

File metadata and controls

64 lines (52 loc) · 1.36 KB

handlebars-jest

Jest Handlebars transformer

Usage

npm install --save-dev handlebars-jest

Setup

To define handlebars-jest as a transformer for your .hbs files, you need to map .hbs files to the handlebars-jest module.

{
  "jest": {
    "transform": {
      "^.+\\.hbs$": "<rootDir>/node_modules/handlebars-jest"
    }
}

Additional options

Configure the transformer in a handlebars-jest property in your Jest config's globals.

{
  "jest": {
    "transform": {
      "^.+\\.hbs$": "handlebars-jest"
    },
    "globals": {
      "handlebars-jest": {
        "helperDirs": [
          "/some/absolute/path/to/helpers",
          "<rootDir>/another/helpers/path"
        ],
        "helperExtensions": [
          ".js",
          ".mjs"
        ],
        "partialDirs": [
          "/some/absolute/path/to/partials",
          "<rootDir>/another/partials/path"
        ],
        "partialExtensions": [
          ".hbs",
          ".html"
        ]
      }
    }
  }
}

The following options are supported:

  • helperDirs: Defines directories to be searched for helpers.
  • helperExtensions: Defines valid filename extensions for helpers. Default is ['.js'].
  • partialDirs: Defines directories to be searched for partials.
  • partialExtensions: Defines valid filename extensions for partials. Default is ['.hbs', '.handlebars'].