javascript

A 8-post collection

removeEventListener and this

Have you ever tried to call removeEventListener on a previously attached element and couldn't remove it? Did you maybe try to pass a function to addEventListener that is bound to another context? The context of the callback that we are passing to addEventListener is the same as the event.currentTarget when is being called. The problem is that when we bind the callback to another object, we can't remove it afterward. Lets see an example: let element = document.createElement('button') »

Isolated Unit Tests with Sinonjs

Units in Unit Testing is the smallest unit of code. But how small? Small enough to be tested. For that matter, Unit Tests need to be isolated and for that you need stubs. Here I will use a small function and the Sinonjs to try to test it. My function does some checks and finally an HTTP call to an external service while similar functions would hit a DB. But our intention is to test the actual function and we »

Automated GUI Testing Solutions

I gave a talk entitled TDD with Node.js in the latest SKGNode.js meetup. I explained the concept of TDD and described my tools of choice for integrating the TDD flow with Node.js. It was great. I didn't got into GUI testing and I saw a major interest on that. So I decided to take a look at the current state of GUI testing. Here are the main tools that I came up with: Zombie.js Zombie uses »

Node.js & Recursion

Recursion is one of the initial courses we take in every CS university, with the most used example being the Fibonacci sequence: let recursive = (n) => { if(n This works great in most of the languages we've been taught, but with asynchronous environments such as Node.js, things are getting tricky. Using asynchronous functions, we need to wait for the function to end before call the next iteration of the recursion. Say we need to recursively delete an item and all »

The road to Client Side Javascript

Client Side JS frameworks have come a long way. Since the rise of Backbone.js back at 2010, the way we write Javascript and everything about it has changed. A lot of frameworks have born, almost one for every need. But what does a Client Side JS framework consists of? Should I adopt one out of the wild or write my own? As always, it depends. And you should do your homework before choosing one or the other. I've come »