windyGex / preact-compat-enzyme

Implement React internal properties

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any advice for Jest?

screendriver opened this issue Β· 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 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

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

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

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"
}

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