preact-compat-enzyme icon indicating copy to clipboard operation
preact-compat-enzyme copied to clipboard

Any advice for Jest?

Open screendriver opened this issue 7 years ago • 5 comments

Do you have any advice for testing with Jest? I've got two projects that are using Jest as test runner. One uses webpack and one doesn't use webpack. Both are written in TypeScript and both use preact.

I don't get it working 😞

screendriver avatar Apr 25 '17 14:04 screendriver

@screendriver have you looked into preact-boilerplate ? It is using Jest but without their asserts. You have to do your own rendering of the components + assertion or use preact-jsx-chai for assertions.

The preact-compat-enzyme should be used when you want to use preact-compat for your react components + support for your react specific tests written in enzyme

fokusferit avatar Apr 26 '17 12:04 fokusferit

same problem here TS + Preact + PReact-compat, doesn't work with this package

"moduleNameMapper": {
    "react-dom/server$": "<rootDir>/node_modules/preact-render-to-string/index.js",
    "react-addons-test-utils": "<rootDir>/node_modules/preact-test-utils/dist/index.js",
    "react-addons-transition-group$": "<rootDir>/node_modules/preact-transition-group/dist/preact-transition-group.js",
    "react$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js",
    "react-dom$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js"
  }

--> TypeError: preact.h is not a function

Hotell avatar May 12 '17 10:05 Hotell

I also get the preact.h is not a function error...

dcolthorp avatar May 31 '17 19:05 dcolthorp

Not sure if it's still relevant but to put it on record this can be fixed by adding a ^ to the start of the regex

"moduleNameMapper": {
    "^react-dom/server$": "<rootDir>/node_modules/preact-render-to-string/index.js",
    "^react-addons-test-utils$": "<rootDir>/node_modules/preact-test-utils/dist/index.js",
    "^react-addons-transition-group$": "<rootDir>/node_modules/preact-transition-group/dist/preact-transition-group.js",
    "^react$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js",
    "^react-dom$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js"
}

bkazi avatar Aug 30 '17 07:08 bkazi

Using following config.

module.exports = {
  "moduleNameMapper": {
    "^react-dom/server$": "<rootDir>/node_modules/preact-render-to-string/dist/index.js",
    "^react-addons-test-utils$": "<rootDir>/node_modules/preact-test-utils/lib/index.js",
    "^react$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js",
    "^react-dom$": "<rootDir>/node_modules/preact-compat-enzyme/lib/index.js"
  }
}

And there is an example project

windyGex avatar Aug 31 '17 03:08 windyGex