Search code examples
typescriptjestjsenzymeblueprintjs

Blueprintjs with `jest` does not work


I have a very simple test.

in my package.json it looks like this

"jest": {
  "transform": {
    ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
  },
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
  "ts",
  "tsx",
  "js"
],
"globals": {
  "__TS_CONFIG__": "./tsconfig.json"
}
}

My test looks like this.

import * as React from "react";
import {} from "jest";
import { shallow } from "enzyme";
jest.unmock('classnames')
jest.unmock('../src/browser/browser');
import { Browser } from "../src/browser";


describe("Browser tests", function() {
  test("test the browser loads", () => {
    expect(3).toBe(3);
    expect(shallow(<Browser />).contains(<div className="foo" 
  />)).toBe(true);
});
});

I get this error

/Users/..../node_modules/@blueprintjs/core/src/components/non-ideal-state/nonIdealState.tsx:8`
import * as classNames from "classnames";
^^^^^^
SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:290:17)

What is it that I am doing wrong? Any help would be appreciated

I am using jest- 20.0.1 enzyme-2.8.2 ts-jest-20.0.3 blueprint-core 1.16.0


Solution

  • The problem was on one of the components I was importing from blueprintjs/core/src modules. I took off that and it worked.