Wrapping PrimeUI component into React component - reactjs

As a proof of concept I'm trying to use PrimeUI as a basis to build React components. There is an article explaining how to do it by Michael Guterl. It works in JSFiddle
var Component = React.createClass({
componentDidMount: function() {
var themes = new Array('afterdark', 'afternoon');
$(ReactDOM.findDOMNode(this)).puidropdown({
data: themes,
editable: true
});
},
render: function() {
return <select / >
}
});
ReactDOM.render( < Component / > , document.getElementById('container'));
but I'm unable to make it work from the inside React application. The error I have 'piudropdown - is not a function' indicates that primeUI is not picked up or somehow not applied. Obviously, I have jquery, jquery-ui and primeui dependencies in package.json. I also can see some primeui related staff in my bundled js file, therefore it is included. So does anyone have any ideas what could be wrong or missing? Is there any suggestions how to debug that sort of issues?
The component JS
var React = require('react');
require('jquery');
require('jquery-ui');
require('primeui');
var ReactDOM = require('react-dom');
var MyComponent = React.createClass({
componentDidMount: function() {
$(ReactDOM.findDOMNode(this)).puidropdown();
},
render: function() {
return (
<select/>
)
}
});
module.exports = MyComponent;
package.json
{
"name": "xxx-react",
"version": "0.0.1",
"description": "React UI for XXX",
"private": true,
"scripts": {
"start": "node start.js",
"test": "karma start karma.conf.js"
},
"dependencies": {
"body-parser": "1.14.0",
"bower": "^1.4.1",
"browserify": "13.0.0",
"babelify": "7.2.0",
"del": "1.1.0",
"es5-shim": "4.0.5",
"eslint-plugin-react": "4.3.0",
"babel-eslint": "6.0.2",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"express": "4.10.6",
"extend": "3.0.0",
"gulp": "3.9.0",
"gulp-concat": "^2.4.2",
"gulp-connect": "2.3.1",
"gulp-cssmin": "^0.1.6",
"gulp-eslint": "^2.0.0",
"gulp-sass": "2.1.0",
"gulp-uglify": "^1.0.2",
"gulp-util": "^3.0.1",
"jasmine-core": "^2.3.4",
"jquery": "2.1.3",
"jquery-ui": "latest",
"karma": "0.13.22",
"karma-browserify": "5.0.3",
"karma-chrome-launcher": "0.2.3",
"karma-firefox-launcher": "0.1.7",
"karma-cli": "0.1.2",
"karma-jasmine": "0.3.6",
"karma-junit-reporter": "0.4.2",
"lodash": "4.11.0",
"moment": "2.9.0",
"react": "15.0.1",
"react-dom": "15.0.1",
"react-addons-test-utils": "15.0.1",
"react-bootstrap": "0.28.5",
"react-router-bootstrap": "0.22.0",
"react-bootstrap-daterangepicker": "0.2.3",
"react-router": "2.1.1",
"reflux": "0.4.1",
"vinyl-buffer": "1.0.0",
"vinyl-source-stream": "^1.0.0",
"watchify": "3.7.0",
"primeui" : "latest"
},
"engines": {
"node": "0.10.x"
},
"devDependencies": {
"eslint": "2.7.0"
}
}

While many people struggle to make jquery and jquery-ui to work together when using browserify, in my case it wasn't actually the case. In our setup, we have two bundled js files vendor.js and app.js. The vendor.js includes jquery, slick and es5-shim while all the js sources of the application compiled into app.js file. The problem solved by including jquery-ui and primeui into vendor.js file, so they loaded together with jquery.

Related

vue2 to react migration, tsx module not found

I have a vue2 app which does not implement typescript. I have decided to migrate the app to react. Thought process is to implement new features in react and let the old features run in vue. This is what I have done so far.
Created a new react-migration folder which will have all the new features.
Tried two ways to use the HelloWorld component
Create a react wrapper which takes the react component and renders it.
<template>
<div ref="container" />
</template>
<script>
import { createElement } from "react";
import { createRoot } from "react-dom/client";
export default {
inheritAttrs: false,
props: {
component: {
type: Function,
required: true,
},
},
data() {
return {
reactRoot: null,
};
},
watch: {
$attrs: {
deep: true,
handler() {
this.updateReactComponent();
},
},
},
mounted() {
this.reactRoot = createRoot(this.$refs.container);
this.updateReactComponent();
},
destroyed() {
this.reactRoot.unmount();
},
methods: {
updateReactComponent() {
this.reactRoot.render(createElement(this.component, this.$attrs));
},
},
};
</script>
Used veaury package to do the same.
Issue :
I have added all the ext in the config file.
extensions: ['*', '.js', '.vue', '.json','.tsx','.ts','.jsx']
I believe its because my vue project is not able to recognise the react tsx file.
All the help is appreciated.
Implementation reference articles
Veary implementation reference
React to vue migrations reference
package.json dependencies
"dependencies": {
"#cypress/vue": "^2.2.4",
"#fortawesome/fontawesome-svg-core": "^1.2.36",
"#fortawesome/free-brands-svg-icons": "^5.15.4",
"#fortawesome/free-regular-svg-icons": "^5.15.4",
"#fortawesome/free-solid-svg-icons": "^5.15.4",
"#fortawesome/vue-fontawesome": "^2.0.2",
"#tiptap/extension-character-count": "^2.0.0-beta.12",
"#tiptap/extension-collaboration": "^2.0.0-beta.19",
"#tiptap/extension-collaboration-cursor": "^2.0.0-beta.20",
"#tiptap/extension-font-family": "^2.0.0-beta.207",
"#tiptap/extension-highlight": "^2.0.0-beta.14",
"#tiptap/extension-link": "^2.0.0-beta.18",
"#tiptap/extension-table": "^2.0.0-beta.24",
"#tiptap/extension-table-cell": "^2.0.0-beta.13",
"#tiptap/extension-table-header": "^2.0.0-beta.15",
"#tiptap/extension-table-row": "^2.0.0-beta.13",
"#tiptap/extension-task-item": "^2.0.0-beta.16",
"#tiptap/extension-task-list": "^2.0.0-beta.16",
"#tiptap/extension-text-style": "^2.0.0-beta.207",
"#tiptap/extension-typography": "^2.0.0-beta.207",
"#tiptap/extension-underline": "^2.0.0-beta.207",
"#tiptap/html": "^2.0.0-beta.84",
"#tiptap/prosemirror-tables": "^1.1.4",
"#tiptap/starter-kit": "^2.0.0-beta.80",
"#tiptap/vue-2": "^2.0.0-beta.39",
"#vue/babel-preset-jsx": "^1.4.0",
"#vue/cli": "^4.5.15",
"axios": "^0.19.2",
"buefy": "^0.9.4",
"canvg": "^4.0.1",
"core-js": "^2.6.5",
"dompurify": "^2.4.3",
"echarts": "^4.4.0",
"eslint-plugin-cypress": "^2.12.1",
"google-fonts-webpack-plugin": "^0.4.4",
"hooper": "^0.3.4",
"html2pdf.js": "^0.10.1",
"jspdf": "^2.5.1",
"lodash": "^4.17.21",
"moment": "^2.24.0",
"npm-run-all": "^4.1.5",
"numeral": ">=2",
"postcss-loader": "^3.0.0",
"prosemirror-commands": "^1.5.0",
"prosemirror-history": "^1.3.0",
"prosemirror-keymap": "^1.2.0",
"prosemirror-schema-list": "^1.2.2",
"raw-loader": "^0.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.57.1",
"sass-rem": "^3.0.0",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"veaury": "^2.3.11",
"vee-validate": "^3.2.1",
"vue": "^2.6.10",
"vue-axios": "^2.1.5",
"vue-carousel": "^0.18.0",
"vue-class-component": "^7.1.0",
"vue-content-loading": "^1.6.0",
"vue-drawer-layout": "^1.3.0",
"vue-echarts": "^4.0.4",
"vue-html2pdf": "^1.8.0",
"vue-i18n": "^8.0.0",
"vue-jwt-decode": "^0.1.0",
"vue-line-clamp": "^1.3.2",
"vue-moment": "^4.0.0",
"vue-numerals": "^3.0.5",
"vue-router": "^3.1.3",
"vue-star-rating": "^1.6.1",
"vuedraggable": "^2.23.2",
"vuex": "^3.1.2",
"webpack-dev-server": "^4.7.4",
"y-indexeddb": "^9.0.6",
"y-websocket": "^1.3.15",
"yjs": "^13.5.10"
},
"devDependencies": {
"#iconify/icons-icomoon-free": "^1.2.3",
"#iconify/vue2": "^2.0.1",
"#kazupon/vue-i18n-loader": "^0.3.0",
"#types/uuid": "^9.0.0",
"#vue/cli-plugin-babel": "^3.11.0",
"#vue/cli-plugin-eslint": "^3.11.0",
"#vue/cli-service": "^3.11.0",
"#vue/eslint-config-prettier": "^5.0.0",
"babel-eslint": "^10.0.3",
"cache-loader": "^4.1.0",
"css-loader": "^3.2.1",
"cypress": "^12.3.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^5.2.3",
"file-loader": "^3.0.1",
"prettier": "^1.19.1",
"sass-loader": "^7.1.0",
"url-loader": "^2.1.0",
"vue-cli-plugin-i18n": "^0.6.0",
"vue-eslint-parser": "^7.0.0",
"vue-template-compiler": "^2.6.14",
"webpack": "^4.46.0"
}

SyntaxError: unknown: Support for the experimental syntax 'jsx' isn't currently enabled

I am making my first ever unit tests with Jest and React Testing Library on my react app.
This is a project I took over and has some pre-existing configuration and test setup which I'll admit I may not fully understand.
How I got to this error is this:
I already had one test up and running testing a component that doesn't use redux.
My next test needed to test a component that uses Redux and so I started to look at totally using React Testing Library and dropping Enzyme all together as the Enzyme isnt compatible with the latest React.
I kept getting an error along the lines of 'cannot import modules outside of node modules' and found out that babel cannot parse ES6.
And so I have been scouring the internet looking for solutions...
I have tried a few methods:
#babel/plugin-syntax-jsx
#babel/preset-react
most recently
However it seems it was not being picked up on as I was still getting the same error with the same suggestion which was:
Add #babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add #babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
I have added this to the presets and plugins of my babel config in my package-lock but still got the same error.
I also tried adding a .babelrc and babel.config.js file with the same preset and plugins but still get the same error.
There was some pre-existing code which I think could potentially be screwing things up somehow but I do not entirely understand it I'll be honest.
This is my package-lock:
{
"name": "hiro-flash",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.4",
"#sentry/react": "^5.29.2",
"#sentry/tracing": "^5.29.2",
"autoprefixer": "7.1.6",
"axios": "^0.18.0",
"axios-cache-adapter": "^2.3.3",
"babel-core": "6.26.0",
"babel-eslint": "^8.2.6",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
"babel-preset-react-app": "^3.1.2",
"babel-runtime": "6.26.0",
"bluebird": "^3.5.1",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
"copy-to-clipboard": "^3.3.1",
"css-loader": "0.28.7",
"detect-browser": "^2.5.0",
"dotenv": "4.0.0",
"dotenv-expand": "4.2.0",
"eslint": "^4.19.1",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.4.0",
"export-to-csv": "^0.2.1",
"express": "^4.16.3",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.5",
"file-saver": "^2.0.5",
"fs-extra": "3.0.1",
"html-webpack-plugin": "2.29.0",
"jest": "26.6.3",
"jest-cli": "26.6.3",
"jest-esm-transformer": "^1.0.0",
"jquery": "^3.3.1",
"jszip": "^3.6.0",
"jszip-utils": "^0.1.0",
"lodash": "^4.17.10",
"moment": "2.18.1",
"moment-business-days": "^1.1.3",
"moment-timezone": "^0.5.23",
"npm": "^5.10.0",
"object-assign": "4.1.1",
"path": "^0.12.7",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.8",
"promise": "8.0.1",
"prop-types": "^15.6.2",
"raf": "3.4.0",
"react": "latest",
"react-accessible-accordion": "^3.3.3",
"react-dates": "^21.2.1",
"react-datetime": "^2.15.0",
"react-dev-utils": "^5.0.2",
"react-device-detect": "^1.9.10",
"react-dom": "latest",
"react-dropzone": "^11.3.2",
"react-ga": "3.2.0",
"react-hotjar": "^2.2.1",
"react-hover-observer": "^2.1.0",
"react-html-parser": "^2.0.2",
"react-quill": "^1.3.1",
"react-redux": "^5.0.7",
"react-responsive-modal": "^2.1.0",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.8",
"react-select": "^2.0.0",
"react-sizes": "^1.0.4",
"react-table": "6.8.6",
"react-throttle-render": "^2.0.0",
"react-tippy": "^1.2.2",
"react-toastify": "^6.0.9",
"react-tooltip": "^4.2.11",
"recharts": "^1.8.5",
"redux": "^3.7.2",
"redux-api-middleware": "^2.3.0",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.0",
"redux-thunk": "^2.3.0",
"style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
"url-loader": "0.6.2",
"webpack": "3.8.1",
"webpack-dev-server": "2.9.4",
"webpack-manifest-plugin": "1.3.2",
"whatwg-fetch": "2.0.3",
"xlsx": "^0.16.9"
},
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "jsdom",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx)$": "jest-esm-transformer",
"^.+\\.(mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"mjs",
"js",
"json",
"web.jsx",
"jsx",
"node"
]
},
"extensionsToTreatAsEsm": [
".js",
".jsx",
".ts"
],
"globals": {
"window": {
"location": {
"protocol": {}
}
}
},
"babel": {
"plugins": [
"#babel/plugin-syntax-jsx"
],
"presets": [
"#babel/preset-env",
"#babel/preset-react",
"react-app"
]
},
"eslintConfig": {
"extends": "react-app"
},
"devDependencies": {
"#babel/plugin-syntax-jsx": "^7.14.5",
"#testing-library/react": "^12.0.0",
"chai": "^4.2.0",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.6",
"node-sass": "^4.9.3",
"react-test-renderer": "^16.14.0",
"sass-loader": "^6.0.7",
"sinon": "^7.4.1"
}
}
this is my test:
import React from 'react';
import renderer from 'react-test-renderer';
import { PriceMonitor } from '../../components/priceMonitor/PriceMonitor';
describe('Price Monitor', () => {
const getTree = (activeUser = 'Test User 1', isOriginalUser = true, openPriceMonitorModal = jest.fn(),
resetActiveUser = jest.fn()) => {
const props = {
activeUser,
openPriceMonitorModal,
isOriginalUser,
resetActiveUser,
}
const component = renderer.create(<PriceMonitor {...props} />);
return component.toJSON();
}
const mockOnClick = jest.fn((username, newOriginalValue) => getTree(username, newOriginalValue));
it('renders original user (Test User 1)', () => {
const tree = getTree();
expect(tree).toMatchSnapshot();
});
it('changes user onClick (Test User 1 -> Test User 2)', () => {
const tree = getTree();
expect(tree).toMatchSnapshot();
expect(mockOnClick('Test User 2', false)).toMatchSnapshot();
});
it('renders non original user (Test User 2)', () => {
const tree = getTree('Test User 2', false)
expect(tree).toMatchSnapshot();
});
it('resets user onClick (Test User 2 -> Test User 1)', () => {
const tree = getTree('Test User 2', false);
expect(tree).toMatchSnapshot();
expect(mockOnClick('Test User 1', true)).toMatchSnapshot();
});
});
And then 2 files which were pre-existing,
this is test.js:
'use strict';
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err;
});
// Ensure environment variables are read.
require('../config/env');
const jest = require('jest');
const argv = process.argv.slice(2);
// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
argv.push('--watch');
}
jest.run(argv);
fileTransform.js inside my jest folder:
'use strict';
const path = require('path');
// This is a custom Jest transformer turning file imports into filenames.
// http://facebook.github.io/jest/docs/en/webpack.html
module.exports = {
process(src, filename) {
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
},
};
Theres also a webpack.config.dev.js but Im not sure how much that is effecting this problem
Im a newb so apologies if this isnt clear enough - will be happy to provide more info.

react-intl with react-testing-library gives Invalid hook call error

in our project we use react-intl for internationalisation. We are using jest as the testing framework and we decided to move our unit test utility library from enzyme to react-testing-library. But now, since there is no shallow rendering, I have to provide <IntlProvider ... /> in the test myself, no problem. But even if I do that, when testing terminal says Invalid hook call. Hooks can only be called inside of the body of a function component but when I run the project locally, no errors just runs normally as expected. P.S in the tests, Apollo provider works normally.
FirstNameFor.test.tsx
import { IntlProvider } from 'react-intl';
import { createMockClient } from 'mock-apollo-client';
import { ApolloProvider as ApolloProviderHooks } from '#apollo/react-hooks';
import { ApolloProvider } from 'react-apollo';
const wrapper = (mockProps, mockClient) => {
return (
<ApolloProvider client={mockClient}>
<ApolloProviderHooks client={mockClient}>
<IntlProvider locale="en">
<FirstNameForm
handleNext={mockProps.handleNext}
onboardingState={mockProps.onboardingState}
setHelpContent={mockProps.setHelpContent}
updateOnboardingState={mockProps.updateOnboardingState}
/>
</IntlProvider>
</ApolloProviderHooks>
</ApolloProvider>
);
};
describe('FirstNameForm Container', () => {
afterEach(() => {
jest.clearAllMocks();
cleanup();
});
it('should match snapshot', () => {
// Arrange
const mockProps = {
handleNext: jest.fn(),
onboardingState: {},
setHelpContent: jest.fn(),
updateOnboardingState: jest.fn(),
};
const mockClient = createMockClient();
// Act
const component = render(wrapper(mockProps, mockClient));
// Assert
expect(component).toMatchSnapshot();
});
});
FirstNameForm.tsx
export const FirstNameForm: React.FC<StepContentProps> = props => {
const [showMessageMutation] = useShowMessageMutation();
const intl = useIntl();
const formik = useFormik<FirstNameFormValues>({
...,
});
return <FirstNameFormComponent formik={formik} intl={intl} />;
};
Terminal Screenshot
package.json
{
"private": true,
"proxy": "http://localhost:5000",
"version": "0.1.57",
"scripts": {
"dev": "yarn graphql:generate && SKIP_PREFLIGHT_CHECK=true react-app-rewired start",
"build": "SKIP_PREFLIGHT_CHECK=true react-app-rewired build",
"testonly": "SKIP_PREFLIGHT_CHECK=true react-app-rewired test --env=jsdom",
"coverage": "SKIP_PREFLIGHT_CHECK=true react-app-rewired test --env=jsdom --coverage",
},
"jest": {
"coveragePathIgnorePatterns": [
"/node_modules/",
"src/types/",
"src/config/analytics/mp.d.ts",
"src/config/analytics/ua.d.ts"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"resolutions": {
"#types/react": "16.8.17"
},
"dependencies": {
"#apollo/react-hooks": "3.1.3",
"animated-scroll-to": "1.2.2",
"apollo-cache": "1.3.2",
"apollo-cache-inmemory": "1.6.3",
"apollo-client": "2.6.3",
"apollo-link": "1.2.12",
"apollo-link-context": "1.0.18",
"apollo-link-error": "1.1.11",
"apollo-link-http": "1.5.15",
"apollo-link-ws": "1.0.18",
"apollo-utilities": "1.3.2",
"big.js": "5.2.2",
"copy-to-clipboard": "3.2.0",
"core-js": "3.0.1",
"date-fns": "1.30.1",
"downloadjs": "1.4.7",
"formik": "2.1.1",
"graphql": "14.3.0",
"graphql-subscriptions": "1.1.0",
"graphql-tag": "2.10.1",
"graphql-tools": "4.0.4",
"history": "4.9.0",
"intl": "1.2.5",
"js-cookie": "2.2.0",
"lodash": "4.17.11",
"owasp-password-strength-test": "1.3.0",
"qrcode.react": "0.9.3",
"query-string": "6.5.0",
"react": "16.8.6",
"react-apollo": "3.1.3",
"react-dom": "16.8.6",
"react-google-recaptcha": "1.1.0",
"react-intl": "3.1.8",
"react-router-dom": "5.1.0",
"recompose": "0.30.0",
"regenerator-runtime": "0.13.2",
"subscriptions-transport-ws": "0.9.16",
"validator": "10.11.0",
"victory": "34.0.0",
"yup": "0.27.0"
},
"devDependencies": {
"#apollo/react-testing": "3.1.3",
"#babel/cli": "7.4.4",
"#babel/core": "7.4.4",
"#babel/preset-env": "7.4.4",
"#graphql-codegen/add": "1.8.1",
"#graphql-codegen/cli": "1.8.1",
"#graphql-codegen/fragment-matcher": "1.8.1",
"#graphql-codegen/typescript": "1.8.1",
"#graphql-codegen/typescript-operations": "1.8.1",
"#graphql-codegen/typescript-react-apollo": "1.8.1",
"#testing-library/react": "10.0.4",
"#testing-library/jest-dom": "5.8.0",
"#types/testing-library__react": "10.0.1",
"#types/big.js": "4.0.5",
"#types/downloadjs": "1.4.1",
"#types/enzyme": "3.10.5",
"#types/graphql": "14.2.0",
"#types/js-cookie": "2.2.2",
"#types/node": "12.0.0",
"#types/owasp-password-strength-test": "1.3.0",
"#types/prop-types": "15.7.1",
"#types/qrcode.react": "0.8.2",
"#types/query-string": "6.3.0",
"#types/react": "16.8.17",
"#types/react-dom": "16.8.4",
"#types/react-google-recaptcha": "1.0.0",
"#types/react-router-dom": "5.1.0",
"#types/react-test-renderer": "16.9.0",
"#types/recompose": "0.30.6",
"#types/validator": "10.11.0",
"#types/victory": "33.1.0",
"#types/ws": "6.0.1",
"#types/yup": "0.26.13",
"babel-loader": "8.0.6",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.2",
"enzyme-to-json": "3.4.4",
"jest-canvas-mock": "2.2.0",
"jest-localstorage-mock": "2.4.0",
"merge-graphql-schemas": "1.5.8",
"npm-run-all": "4.1.5",
"patch-package": "6.1.2",
"postinstall-postinstall": "2.0.0",
"react-app-rewired": "2.1.3",
"react-scripts": "3.3.0",
"react-test-renderer": "16.8.6",
"source-map-explorer": "1.8.0",
"ts-jest": "25.3.1",
"ts-node": "8.1.0",
"typescript": "3.5.3"
}
}
The error comes from React itself, and most likely has nothing to do with react-intl.
There's a good chance you have multiple instances of React in conflict, for some reason only occurring in the test environment. I suspect it might have to do with react-app-rewired, not sure though.
The steps from the official help doc should help reveal whether duplicate Reacts is the source of the problem.
If that is the reason, here's some of the top solutions from the community:
Modify your webpack config to resolve the react alias (discussion)
resolve: {
alias: {
react: path.resolve('./node_modules/react'),
}
},
Modify your webpack config to set react as an external (PR example)
externals: {
react: 'react'
}
Or one of these other miscellaneous approaches

Not able to add new modules to AngularJs Boilerplate

I am working on an angular project and have decided to use a boilerplate for it. Here is the link to the boilerplate: https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate
The problem i am facing is that i am unable to add any new moudle.
e.g i wanted to add ngCart via npm. I have installed it but it is not accessible in the code.
`import angular from 'angular';
// angular modules
import constants from './constants';
import onConfig from './on_config';
import onRun from './on_run';
import 'angular-ui-router';
import 'ngCart'; //this doesn't import it
import './templates';
import './filters';
import './controllers';
import './services';
import './directives';
// create and bootstrap application
const requires = [
'ui.router',
'ngCart',
'templates',
'app.filters',
'app.controllers',
'app.services',
'app.directives'
];
// mount on window for testing
window.app = angular.module('app', requires);
angular.module('app').constant('AppSettings', constants);
angular.module('app').config(onConfig);
angular.module('app').run(onRun);
angular.bootstrap(document, ['app'], {
strictDi: true
});
My package.json is
{
"name": "angularjs-gulp-browserify-boilerplate",
"version": "1.7.1",
"author": "Jake Marsh <jakemmarsh#gmail.com>",
"description": "Boilerplate using AngularJS, SASS, Gulp, and Browserify while also utilizing best practices.",
"repository": {
"type": "git",
"url": "https://github.com/jakemmarsh/angularjs-gulp-browserify-boilerplate.git"
},
"license": "MIT",
"keywords": [
"express",
"gulp",
"browserify",
"angular",
"sass",
"karma",
"jasmine",
"protractor",
"boilerplate"
],
"private": false,
"engines": {
"node": "~4.2.x"
},
"scripts": {
"dev": "cross-env NODE_ENV=development ./node_modules/.bin/gulp dev",
"build": "cross-env NODE_ENV=production ./node_modules/.bin/gulp prod",
"deploy": "cross-env NODE_ENV=production ./node_modules/.bin/gulp deploy",
"test": "cross-env NODE_ENV=test ./node_modules/.bin/gulp test",
"protractor": "cross-env NODE_ENV=test ./node_modules/.bin/gulp protractor",
"unit": "cross-env NODE_ENV=test ./node_modules/.bin/gulp unit"
},
"dependencies": {
"cross-env": "^3.1.1",
"ngCart": "1.0.0"
},
"devDependencies": {
"angular": "^1.5.0",
"angular-mocks": "^1.3.15",
"angular-ui-router": "^0.3.1",
"babel-core": "^6.3.26",
"babel-eslint": "^7.0.0",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.5.2",
"babelify": "^7.2.0",
"brfs": "^1.2.0",
"browser-sync": "^2.7.6",
"browserify": "^13.0.0",
"browserify-istanbul": "^2.0.0",
"browserify-ngannotate": "^2.0.0",
"bulk-require": "^1.0.0",
"bulkify": "^1.1.1",
"debowerify": "^1.3.1",
"del": "^2.1.0",
"envify": "^3.4.0",
"ngCart": "^1.0.0",
"eslint": "3.7.1",
"express": "^4.13.3",
"gulp": "^3.9.0",
"gulp-angular-templatecache": "^2.0.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-changed": "^1.0.0",
"gulp-eslint": "^3.0.1",
"gulp-gzip": "^1.2.0",
"gulp-if": "^2.0.0",
"gulp-imagemin": "^3.0.3",
"gulp-notify": "^2.0.0",
"gulp-protractor": "^3.0.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "^2.0.4",
"gulp-sass-glob": "^1.0.6",
"gulp-sourcemaps": "^1.6.0",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.1",
"imagemin-pngcrush": "^5.0.0",
"isparta": "^4.0.0",
"karma": "^1.3.0",
"karma-browserify": "^5.0.2",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "douglasduteil/karma-coverage#next",
"karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2",
"karma-sauce-launcher": "^1.0.0",
"merge-stream": "^1.0.0",
"pretty-hrtime": "^1.0.1",
"run-sequence": "^1.1.5",
"tiny-lr": "^0.2.1",
"uglifyify": "^3.0.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.7.0"
}
}
ngCart does not have a main key in its package.json, nor an index.js at its root, so import can not know what to import. So you need to be a little more explicit in your import statement.
try to replace
import 'ngCart'; //this doesn't import it
by
import 'ngCart/dist/ngCart'; //this should do it ;)

React-native/Enzyme : mount throws "unknown props" on native elements

I'm writing tests using Jest & Enzyme in React Native to fully test my components behaviors and inner functions.
Shallow test seems ok but when using mount it just throws
Here's my package.json.
{
"name": "Despirithium",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"buildandroid": "react-native bundle --platform=android --entry-file=index.android.js --bundle-output='android/app/src/main/assets/index.android.bundle?dev=false",
"test": "jest --watch"
},
"dependencies": {
"axios": "^0.15.*",
"dpath": "^2.0.2",
"evosphere-router": "0.1.9",
"immutable": "^3.8.1",
"intl": "^1.2.5",
"lodash": "^4.16.4",
"node-uuid": "^1.4.7",
"normalizr": "^2.2.1",
"react": "15.3.2",
"react-native": "0.36.0",
"react-native-drawer": "^2.3.0",
"react-native-i18n": "^0.1.1",
"react-native-image-picker": "^0.22.12",
"react-native-router-flux": "^3.35.0",
"react-native-tabs": "^1.0.9",
"react-redux": "^4.4.5",
"redux": "^3.6.0",
"redux-immutable": "^3.0.8",
"redux-logger": "^2.7.0",
"redux-thunk": "^2.1.0",
"string-template": "^1.0.0",
"tcomb-form-native": "^0.6.1"
},
"devDependencies": {
"babel-core": "^6.14.0",
"babel-jest": "^17.0.2",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-plugin-transform-remove-console": "^6.8.0",
"babel-polyfill": "^6.13.0",
"babel-preset-latest": "6.14.0",
"babel-preset-react-native": "^1.9.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"babel-register": "^6.14.0",
"enzyme": "^2.6.0",
"enzyme-to-json": "^1.3.0",
"faussaire": "^0.2.2",
"faussaire-util": "^0.1.0",
"jest": "^17.0.3",
"jest-enzyme": "^2.0.0",
"jest-react-native": "^17.0.3",
"react-addons-test-utils": "15.3.2",
"react-dom": "15.3.2",
"react-native-fs": "^2.0.1-rc.2",
"react-native-mock": "^0.2.7",
"react-test-renderer": "15.3.2",
"updtr": "^0.2.1"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"setupTestFrameworkScriptFile": "node_modules/jest-enzyme/lib/index.js",
"testEnvironment": "jsdom",
"moduleFileExtensions": [
"js",
"json",
"es6"
],
"preset": "jest-react-native"
}
}
For now my test is pretty simple.
global.Promise = require.requireActual('promise');
import 'react-native';
import React from 'react';
import { mount, shallow } from 'enzyme';
import { mountToJson } from 'enzyme-to-json';
import { LoginScene } from '../../../../../../src/bundles/application/ui/scene/public/LoginScene';
import configureStore from '../../../../../../src/configureStore';
import { Provider } from 'react-redux';
import { getState, getInstance } from '../../../../../../src/testing/enzymeUtils';
test('LoginScene', async () => {
const store = await configureStore();
let loginScene;
const wrapper = mount(
<Provider store={store}>
<LoginScene/>
</Provider>
);
expect(mountToJson(wrapper)).toMatchSnapshot();
loginScene = wrapper.find(LoginScene);
getInstance(loginScene)._handleFieldChange('username', 'despirithium');
getInstance(loginScene)._handleFieldChange('password', 'azerty');
expect(getState(wrapper.find(LoginScene)).username).toBe('despirithium');
expect(getState(wrapper.find(LoginScene)).password).toBe('azerty');
});
I would have shallow rendered this but since I need to wrap my scene into the Provider it's not possible.
You may need to wrap Provider in a div. "...Components must return a single root element..." -https://facebook.github.io/react/docs/components-and-props.html

Resources