Angular Unit Testing Snippets for VSCode (Angular 2+)
Visual Studio Code Angular Unit Testing Snippets in Jasmine
These snippets were created after observing that, these code blocks / mocks / techniques were used a lot while we write unit tests in angular.
If you want to learn angular unit testing. Please refer https://angular.io/guide/testing
Type jat- to get the snippet intellisense. Press enter to select a snippet
||Unfold the unit test setup for component (Runs in isolation)
||Component unit test setup with a sample mock service (Runs in isolation)
||Mock service which returns an observable, to use in useClass provider
||Generates a jasmine describe block (Test suite)
||Generates an it block (Test spec)
||Generates a it block to test the methods which contains timers (SetTimeout, SetInterval etc)
||Angular useValue provider to inject mock value as dependency instead of an injection token or injected service.
||Angular useClass provider to inject a mock class as dependency instead of an injection token or injected service.
||Mock Class to use as a mock for the injected Router class (Has minimal methods like navigate, navigateByUrl etc. These can be extended)
||Spec that makes use of angular HttpTestingController to test http requests
||Spec that makes use of angular HttpTestingController to test http requests that may return error
||Spec that dispatches an event to simulate user interactions in unit tests
||Generates an empty before each block
||Creates an asynchronous before each block (Deprecated)
||Creates an asynchronous before each block
||Creates a before each block for testing your service
||Utilizes TestBed to inject a service instance (From Angular 9)
||Utilizes TestBed to inject a service instance (Before Angular 9)