python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
4 e2e Testing

What Is Angular Test Function?

What Is Test Function?
After installing everything as per your project requirements, CREATE your project.
The following Steps –
·             ng new YourTestProject
·             ng install
·             ng serve/ng test

If you are going to development then type “ng server” command and if you want to test your project, you should type “ng test” command.  After type “ng test” command and press enter. It’s taking some time to installing everything in your project for a test.

Test functions–
1.         describe – Test suit (just a function)
2.         it  - The spec or test
3.         expect -  Expected outcome.

Triple Rule of Testing
1.         Arrange - Create and Initialize the Components
2.         Act - Invoke the Methods/Functions of Components
3.         Assert - Assert the expected outcome/behavior

Best Practices - The quick list of best practices.
1.         Use beforeEach() to Initialize the context for your tests.
2.         Make sure the string descriptions you put in describe () and it () make sense as output
3.         Use after () and afterEach () to clean-up your tests if there is any state that may bleed over.
4.         If any one test is over 15 lines of code, you may need to refactor the test

Example -
import { TestBedasync } from '@angular/core/testing';
import { AppComponent } from './app.component';

//describe – Test suit (just a function)
describe('AppComponent', () => {
  beforeEach(async(() => {
      declarations: [AppComponent]

  //it - The spec or test
  it('should have hello property'function() {
  const fixture = TestBed.createComponent(AppComponent);
  const app = fixture.debugElement.componentInstance;

  //expect – this is expected outcome.
   expect(app.hello).toBe('Hello, Anil!');


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions