Monday, January 18, 2021

TypeScript: A basic understanding

  • TypeScript is a superset of JavaScript.
  • TypeScript file gets transpiled into a JavaScript file.
  • TypeScript is all about Types. A JavaScript variable can be assigned with any primitive type. TypeScript on the other hand helps to define the type of a variable.
  • Following are the pre-defined types in TypeScript: boolean, bigint, null, number, string, symbol, object, undefined, any, unknown, never, void.
  • On the other hand, TypeScript provides two syntaxes to build types: Interfaces and Types.
  • Also, TypeScript helps you to create complex types by combining simple ones. There are two popular ways to do so: Unions, Generics.
  • Read more: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html. This page is good enough to get a clear understanding of TypeScript.
Other references:

Jest (just) in Five Minutes

  • What is Jest?
    • Jest is a JavaScript testing framework maintained by Facebook, Inc.
  • Any easy tip to remember the syntactical steps of what you do when you write a test?
    • DIE Matchers (Describe the Test(It) that Expects the result to Match the expectation)
  • How does Jest supports mocking?
    • jest.fn - allows you to mock a function. All mock functions have this '.mock' property.
    • jest.mock - allows you to mock a module (module is the JavaScript module that was exported using module.exports or export default)
    • jest.spyOn - allows you to mock either the whole module or the individual functions of the module. At its most general usage, it can be used to track calls on a method (read this nice article: https://blog.echobind.com/how-to-mock-using-jest-spyon-d13d57a8434d)
    • NOTE: you can't spy something that doesn't exist on the object.
  • How does the mock functions help you in the testing?
    • Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function (and the parameters passed in those calls), capturing instances of constructor functions when instantiated with new, and allowing test-time configuration of return values. Read more: https://jestjs.io/docs/en/mock-functions

What if I try here to cover a little bit on Jasmine?

  • How does Jasmine supports mocking?
    • jasmine.createSpy - to mock a function
    • jasmine.createSpyObj - to mock a module
    • jasmine.spyOn - to mock the individual functions of the module



Wednesday, January 13, 2021

Friday, January 8, 2021

DOM, Shadow DOM, and Virtual DOM

Found this article today that made a good effort in explaining the DOM, Shadow DOM, Virtual DOM and the differences between them.

Read on:

https://www.blog.duomly.com/what-is-the-difference-between-shadow-dom-and-virtual-dom/