Jest-preset-angular: SyntaxError: Unexpected token <

Created on 21 Sep 2017  路  2Comments  路  Source: thymikee/jest-preset-angular

When i'm runnig jest on my project i get this issue:

Test suite failed to run

    c:\projects\meteoguard\src\app\dashboard\briefing-tool\shared\component\accordion\accordion.template.html:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<ng-content></ng-content>

Seems jest tries to requires html file and parse it, and obviously it can't

Most helpful comment

Solved, I override tsconfig path in package.json, and seem it's override the whole global section and removed "__TRANSFORM_HTML__": true flag.

I put it in my config and now it works.

All 2 comments

Solved, I override tsconfig path in package.json, and seem it's override the whole global section and removed "__TRANSFORM_HTML__": true flag.

I put it in my config and now it works.

In later versions solution with "__TRANSFORM_HTML__": true works, but deprecated. The following is recommended way (if through package.json):

  "jest": {
    "globals": {
      "ts-jest": {
        "stringifyContentPathRegex": "\\.html$"
      }
    },
  }
}

https://github.com/kulshekhar/ts-jest/blob/master/docs/user/config/stringifyContentPathRegex.md

Was this page helpful?
0 / 5 - 0 ratings