Skip to main content

Posts

React Testing with Jest and Enzyme

Install enzyme, and enzyme-adapter-react-16 using npm Add the following to setupTests.js file of your project import  {  configure  }  from   'enzyme' ; import   Adapter   from   'enzyme-adapter-react-16' ; configure ({  adapter :   new   Adapter () }); Here is a basic test import   React   from   'react' ; import  {  mount  }  from   'enzyme' ; import   Note   from   './Note' ; const   props  = {      note :   "Test Note" ,      index :   0 ,      removeHandler :   jest . fn () } describe ( 'Note' , ()  =>  {      let   note  =  mount ( < Note   { ... props }   /> );      it ( "renders the note text" , ()  =>  {        ...

Navigation Bar CSS

Navigation Bar CSS Create a navbar using CSS features such as flex and transition. Watch the video.

Error: Invariant failed: You should not use outside a Solution

Solution to error - Error: Invariant failed: You should not use <Switch> outside a <Router> If you are setting up routes using switch and getting the following error: Error: Invariant failed: You should not use <Switch> outside a <Router> Then in that case the solution is simple: wrap your switch with BrowserRouter and import it from react-router-dom See below for example: app.js import   React   from   'react' ; import  {  BrowserRouter ,  Route ,  Switch  }  from   'react-router-dom' ; import   HomePage   from   './components/pages/home/home.component' ; function   App () {    return  (      < div   className = "App" >        < BrowserRouter >          < Switch >            ...

ReactJS Basic App from Pune's Developer Vinit Khandelwal

Vinit Khandelwal is a MERN stack developer from Pune. He has extensive experience in MongoDB, NodeJS, ReactJS, AWS, GCP, and Python. Learn with his snippets on ReactJS and NodeJS. Hello World in ReactJS App Below example is all you need to launch a most basic app in React JS. app.js import React from 'react' ; import ReactDOM from 'react-dom' ; class App extends React . Component { render ( ) { return < h1 > Hello World! </ h1 > ; } } ReactDOM . render ( < App /> , document . getElementById ( 'root' ) ) ;

On running npx create-react-app app-name, template is missing

On creating a react app using npx create-react-app app-name , if your template is missing and you get the following message on terminal: A template was not provided. This is likely because you're using an outdated version of create-react-app. Please note that global installs of create-react-app are no longer supported. then follow the following commands to correct it. First uninstall the package using npm uninstall - g create - react - app then re-install the create-react-app package using the command: npm install -g create - react - app Finally create the app using the following command: npx create - react - app app-name That's it folks!

Windows 10 login screen is blank, no password, restart option visible

I came across a problem that my windows 10 login screen was blank with just background. No password field, or restart option visible. I searched across web but didn't find a solution. I tried some key pairs and one worked. It is as follows: windows key then tab then enter windows key then tab key twice then enter I tried these and one of them worked. So if this works for you then let me know in the comments bellow. Thanks.