Enzyme is created by Airbnb for React component testing. You can easily test components’ output and it works with different testing frameworks like Mocha or Jest. This post focuses on setting up the test environment with Mocha for TypeScript. If you are used to JavaScript and fairly new to TypeScript, …
JavaScript’s sort() method sorts the elements of an array. Sort() takes callback where you can specify sorting rules. By writing a small callback function, array of JSON data can be easily sorted. In this example, we use the JSON array that has name and sore. We will sort this date …
Uploading a file from a browser to S3 for only authorised users is a pretty cool trick. It is even cooler if we can build it in a serverless way. Here is the entire solution for a simple serverless app to authenticate with AWS Cognito and upload a file to …
In a traditional web application, authentication is handled by server-side code and users are managed in the database layer. In the world of serverless apps, we can offload the heavy-lifting to a managed authentication service like AWS Cognito to simplify it. This post focuses on JavaScript code to authenticate users …
setInterval() and setTimeout() functions are the quickest solutions to loop functions with JavaScript, often used for a simple animation effects. For example, setInterval(function(){functionA()}, 1000) executes functionA() every second. On the other hand, setTimeout(function(){functionA()}, 1000) executes functionA() once after waiting for 1 seconds. Both can be stopped by clearInterval() and clearTimeout() …
Sometimes all I need is to see a snippet of code without much explanation when I try to find a solution online. This is because I am familiar enough with the language and framework and need a quick reminder. So, here it is. I created a post with a few …
Jest is a JavaScript unit testing framework created by Facebook. I usually use mocha for unit testing Node.js code, but when it comes to testing React, Jest combined with Enzyme is pretty much the best. Enzyme is a JavaScript utility library created by Airbnb. It lets you simulate DOM rendering …
Now, I have a React development environment with webpack 4 set up on my local Windows 10 machine (How to set up local development environment for React with webpack 4 and babel 7). I have encountered a few occasions that the webpack server suddenly stopped starting and giving me the …
When you think about React, it is basically a Javascript library rather than a framework. This means you can import React library in the script tag in your html file and write an inline code, just like jQuery. I previously wrote a post about setting up React development environment by …