Angular: Observerable vs Promise

Howdy, i’ll keep this sweet, brief and to the point 🙂

Observerable and Promises are in a nutshell ways to handle API responses. Your next question may be on what exactly is the difference, well thanks to this lurrvly tutorial I was able to find out.

In the tutorial JsWiz (not too sure if this is the person’s real name but what do i know) he has a clear image and shows that observables are great for multiple values and they are cancellable. When you subscribe to an Observable it will keep on listening for any changes and updates. Which in some cases are handy, but if you are looking for a simple request and getting a single response then a Promise is what you need i promise you.

the difference between observable and promise

Ok, thats about all i have to say about Observerable and Promises, but if you want to know how to implement it just checkout this linkers

for more info checkout these links:
mdn Promise docs
mdn Observable docs

Unit testing with Enzyme and Jest and Setting up

{/* Before I begin this post is just a how to setup up your project to run unit tests, i’ll probably go over some examples of actual unit tests in a later post. */}

Hello again

So you’re wondering how to make some sweet Unit tests, well so was I. Spoke to my FrontEndFriends, got some high level guidance and I gave it ago to implement it myself.

Here is how to setup up your project with Jest and enzyme.

First thing you’ll need to do is install jest, enzyme and enzyme-adapter-react-16 as a `devDependency`.

So go on install that sucker using npm install jest, enzyme and enzyme-adapter-react-16

npm install jest enzyme enzyme-adapter-react-16 --save-dev

Once all the little packages are installed, you will need to setup the following below.
– add a test-setup.js file
– Add the test-setup.js file to jest.config.json

What does this test-setup.js file need and where does it go? You can use my project as a reference. I made a folder called .jest and added two files:
– shim.js
– test-setup.js

You might be asking “what the heck is a shim folder and what is it doing here?” If you don’t have this file your application starts to complain, so to stop the whinging you’ll need a shim.js in your .jest folder.

Luckily shim.js just consists of the following code:

global.requestAnimationFrame = (callback) => {
setTimeout(callback, 0);
};

Finally, we get to add our test-setup.js here is how mine looks:

// eslint-disable-next-line import/no-extraneous-dependencies
import { configure } from 'enzyme';
// eslint-disable-next-line import/no-extraneous-dependencies
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });

The comments are optional of course.

Now for the next step, that is take test-setup.js file add it to jest.config.json. So navigate to your root directory (where you see all your friends such as package.json and what not and create a file called jest.config.json and add the following code:

{
"verbose": true,
"testURL": "http://localhost/",
"moduleNameMapper": {
"\\.(css|jpg|png)$": "/empty-module.js"
},
"setupFiles": [
"/.jest/shim.js",
"/.jest/test-setup.js"
]

Once all is said and done, add this little guy to your package.json to make running unit tests just a little bit easier

Add a script for `jest`: `jest –config=./jest.config.json –coverage`

Now you should be fully setup if you are running into any problems these references should add some extra guidance happy unit testing!

If you want to do some more reading on unit tests feel free to check out these references:
Jest
Enzyme

How to setup a React project from Scratch with Webpack 4

(tutorial link is a little down below if you don’t want to hear my testimony 😛 )
When I started my adventure of Learning React, going through Facebook’s React tutorials and starting a simple app with the famous, simple, easy to use create-react-app. I thought well this is easy.

When looking up to my colleagues for some advice in getting myself into the React scene and becoming a React Developer. they told me if you want to be taken seriously you have got to know how to create a React project from Scratch.

I heard the framework Webpack being mentioned(yes there are many others don’t worry, but this is what I’ve been exposed to). I went to a colleague for some guidance on how to setup a project from scratch using webpack, i think it was webpack 3.somethingorother.3^ and I was completely lost confused and out of my depth…distraught, flabbergasted, bamboozled, hoodwinked the works.

Problem was I knew I had to learn how to do this. I was searching the net to find a nice tutorial to help me setup a project using webpack and Luckily I came across this tutorial which helped me setup a project from Scratch using webpack

Here is the tutorial:
https://www.valentinog.com/blog/webpack-tutorial/

I do hope that this helps you as much as it helped me…by actually taking me through the steps and getting a working project from Scratch using webpack 4.

Enjoy

I’ll probably be posting a few tutorials on this blog to help others where I’ve been struggling.