Learn free javascript-examples tutorials


Typescript mock interface and async promise example

September 12, 2021 ·  2 min read

In this tutorial, You learned how to test an mock interface in typescript Typescript is an advanced to javascript with strong features like typesafe checking. Jest is an unit testing framework like jasmine from Facebook How to mock an interface in Jest? Let’s declare an interface in typescript with enum being used in interface. role.ts: enum ROLE { ADMIN, SALES, FINANCE } user.ts: export interface User { id: number; name: string; role: ROLE....


Angular component testing - Input text value with test case examples

September 10, 2021 ·  3 min read

In this tutorial, How to unit test input text control on UI form in Angular application. In my previous post, Already discussed about how to read input text value in Angular application. I have existing application created using ng new cli command. Let’s create Angular component using ng g c component command. This creates an angular component. Let’s add input text field and button binding to the template and typescript component....


How to write unit testing static methods in a class of Angular and typescript

September 4, 2021 ·  2 min read

In this tutorial, You learned how to do unit test static methods of a typescript classes. It include an example how to test a component using static method in Angular Let’s declare an ES6 class in typescript with static methods export class StaticClass { static getMessage(name: string): String { return 'Hi' + name + 'Welcome to my blog'; } } Here is an Unit test class for ES6 class with static method...


how to fix 404 errors for webserver during karma unit testing Angular

September 3, 2021 ·  2 min read

In this tutorial, You are going to learn how to fix webserver 404 not found errors in testing angular components or directives. This includes solution for 404 error for loading an assets files like json and images during running karma runner. 2021 01:06:33.123:WARN [web-server]: 404: /assets/arrow.png 2021 01:06:33.123:WARN [web-server]: 404: /assets/down.png Suppose you have a component which uses png or any image files, You will get an error while unit testing an component....


4 ways to test button click event handler in Angular unit testing

September 2, 2021 ·  5 min read

In this tutorial, You learned unit testing button click event in Angular application. In my previous post, Discussed about Angular button click event example Let’s define an angular component - ButtonDemoComponent for button click event In this component, Button displayed and on clicking the button, Click event is called and displays the message to UI element. <div style="text-align:center"> <h1> Angular Button Click Event Example </h1> <button (click)="clickEvent()"> Click Me</button> <h2>{{msg}}</h2> </div> Typescript component...


How to validate decimal numbers in javascript

August 31, 2021 ·  2 min read

In this tutorial, You learned how to validate decimal numbers in javascript Decimal number is a number which are separated by .symbol For example 12.01,22.912 are decimal numbers. In UI form, There are different form validations errors like email, not required and number only. Some times an input form wants validation for decimal numbers only. There are multiple ways we can check regular expression to whether given number is decimal or not Written a function isDecimal, returns true for decimals and false for non decimals Used regular expression string for separated by ....


How to write unit testing for private and static in Angular and typescript

August 26, 2021 ·  2 min read

This tutorials covers how to write a unit testing for private methods in Angular applications. Private methods are private to same class. It is not allowed to access outside can be only accessed in public methods of an typescript class. Angular unit testing for private methods Let’s declare an class export class Employee{ private calculateSalary(){ console.log("Private method to calculate salary") } public getTotalSalary(){ console.log("Return total salary of an employee") } } calculateSalary() is an private method which is accesable in public method getTotalSalary()....


Handlebar for loop iteration array of objects | each helper examples

January 1, 0001 ·  3 min read

Handlebars is a template language for parsing objects in javascript based templates In this tutorials, We learned about each iteration in handler bars and see some examples how to iterate in handlebarjs with examples handlebarJS provides looping with each helper classes using #each helper classe Handlebar JS provides expression templates which need to be enclosed in double curly braces - {{}} each syntax {{#each variable}} {{this}} }} variable is an type of enumerated types like array of objects/types or json objects....


Handlebar if else helper examples| Conditional expression in handlebarJS

January 1, 0001 ·  2 min read

This tutorials covers an handlebar if help classes with examples, it also includes how to test conditional block execution in handlebar mustache templates. HandlebarJS provides {{#if}} and {{#unless}}helper provides an helper to conditional test the expression against javascript objects. if condition in handlebar helps to solve below things Conditional to check an object is null or undefined or empty if and unless are used to check properties of an object not an expressions...


HandlebarJS How to declare comments

January 1, 0001 ·  2 min read

In this tutorial, Learned about how to declare comments in handlebarJS template scripting language. Comments are useful text to describe about line or code component. These will be ignore by compiler or interpreter in any programming language. Does handlebarJS supports comments? Yes It supports and these are used to generate html content by handlebar engine. Does it support inline block and multiline comments? Inline comments are not supported, but support single and multi line comments...


Subscribe
You'll get a notification every time a post gets published here.