Skip to main content

Angular Unit Test Case and Test Bed

 Exclude Angular unit test case from Execution

  • Case using 'x' keyword we can exclude any test case from execution.

  xit('Show the Addition result',() =>{
expect(Addition(10,20)).toBeGreaterThan(20);
    })

Matchers in angular unit test case

  • Matchers are nothing but compare functions to actually compare the expected and actual result in the test specs.
  •  Matchers are the JavaScript function that does a Boolean comparison between an actual output and an expected output.
  • There are two type of matchers Inbuilt matcher and Custom matchers.

Inbuilt Matcher

  • The matchers which are inbuilt in the Jasmine framework are called inbuilt matcher. The user can easily use it implicitly.



TestBed and Component Fixture

  • The Angular Test Bed (ATB) is a higher level Angular Only testing framework that allows us to easily test behaviors that depend on the Angular Framework.
  • We still write our tests in Jasmine and run using Karm but we now have a slightly easier way to create components, handle injection, test asynchronous behavior and interact with our application.

When to Use ATB

  • It allows us to test the interaction of a directive or component with its template.
  • It allows us to easily test change detection.
  • It provide methods to create components and services for unit test case.
  • It allows us to test and use Angular's DI framework.
  •  It allows us to test using the NgModule configuration we use in our application.
  • It allows us to test user interaction via clicks and input fields

Comments

© 2020 The JavaDS Hub

Designed by Open Themes & Nahuatl.mx.