What is the difference between Mocha and Chai JS

Jul 8, 2019

Mocha provides developers with a base test framework, allowing you to have options as to which assertion, moking and spy libraries you want to use. Chai is one of the popular open-source assertion libraries used with Mocha.

References

  • https://amzotti.github.io/testing/2015/03/16/what-is-the-difference-between-a-test-runner-testing-framework-assertion-library-and-a-testing-plugin/
  • https://blog.usejournal.com/jest-vs-mocha-whats-the-difference-235df75ffdf3
Categories : JavaScript

Can Jest be used for unit testing Backbone Application?

Jul 8, 2019

Yes!! We can unit test Backbone JS applications using Jest

References

  • https://github.com/captbaritone/tdd-jest-backbone
  • https://medium.com/@michaelsholty/using-jest-snapshots-in-a-marionette-application-even-with-handlebars-f5c152525006
Categories : JavaScript

What is a HttpOnly cookie?

May 25, 2017

HttpOnly is an additional flag included in Set-Cookie HTTP response header. Using the HttpOnly flag when generating a cookie helps mitigate the risk of client side script accessing the protected cookie (if the browser supports it).

References

  • https://www.owasp.org/index.php/HttpOnly
Categories : HTTP

What are first-class functions?

May 24, 2017

A programming language is said to have first-class functions if it supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data strucures.

JavaScript treats functions as first-class citizens. What this means is that functions in JavaScript are treated as objects. They have the type Object, they can be assigned as the value of a variable, and they can be passed and returned just like any other reference variable.

let handleClick = function() {
    console.log('button clicked');
}

document.getElementById('fooButton').addEventListener('click', handleClick);

References

Categories : Programming   JavaScript

What is a Debounce function?

May 23, 2017

Debounce function returns a function that as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for N milliseconds.

A debounce is a cousin of the throttle, and they both improve the performance of web applications. A debounce is utilized when you only care about the final state. For example, waiting until a user stops typing to fetch typeahead search results.

// Code from https://davidwalsh.name/javascript-debounce-function

var myEfficientFn = debounce(function() {
	// All the taxing stuff you do
}, 250);

window.addEventListener('resize', myEfficientFn); 

The myEfficientFn will not be called until 250 milliseconds has passed since the last resize event.

References

  • https://davidwalsh.name/javascript-debounce-function
  • https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086
Categories : JavaScript