Skip to content

Instantly share code, notes, and snippets.

@codesandtags
Last active May 10, 2018 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codesandtags/f8fd6ec492f5f048431b450ab4ff4f84 to your computer and use it in GitHub Desktop.
Save codesandtags/f8fd6ec492f5f048431b450ab4ff4f84 to your computer and use it in GitHub Desktop.
Live Templates for Angular Projects and Testing
<template name="jdes" value="describe('When $DESCRIBE_NAME$ is invoke', () =&gt; {&#10; it('should $SHOULD_NAME$', () =&gt; {&#10; $END$&#10; });&#10;});" description="Jasmine Describe" toReformat="false" toShortenFQNames="true">
<variable name="DESCRIBE_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="SHOULD_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
<option name="TypeScript" value="true" />
</context>
</template>
<template name="jit" value="it('should $SHOULD_NAME$', () =&gt; {&#10; $END$&#10;});" description="It case" toReformat="false" toShortenFQNames="true">
<variable name="SHOULD_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
<option name="TypeScript" value="true" />
</context>
</template>
<template name="jtc" value="import { async, ComponentFixture, getTestBed, TestBed } from '@angular/core/testing';&#10;import { RouterTestingModule } from '@angular/router/testing';&#10;import { DummyComponent } from '../../mocks/dummy.component.spec';&#10;import { Router } from '@angular/router';&#10;&#10;describe('$COMPONENT_NAME$Component', () =&gt; {&#10;&#10; let component: $COMPONENT_NAME$Component;$END$&#10; let fixture: ComponentFixture&lt;$COMPONENT_NAME$Component&gt;;&#10; let router: Router;&#10; let injector: TestBed;&#10;&#10; beforeEach(&#10; async(() =&gt; {&#10; TestBed.configureTestingModule({&#10; imports: [&#10; RouterTestingModule.withRoutes([{path: 'somepath', component: DummyComponent}])&#10; ]&#10; declarations: [$COMPONENT_NAME$Component],&#10; providers: []&#10; }).compileComponents();&#10; })&#10; );&#10;&#10; beforeEach(() =&gt; {&#10; fixture = TestBed.createComponent($COMPONENT_NAME$Component);&#10; component = fixture.componentInstance;&#10; injector = getTestBed();&#10; router = injector.get(Router);&#10; fixture.detectChanges();&#10; });&#10;&#10; afterAll(() =&gt; {&#10; component = null;&#10; fixture = null;&#10; injector = null;&#10; router = null;&#10; });&#10;&#10; describe('First case', () =&gt; {&#10; it('should ', () =&gt; {&#10;&#10; });&#10; });&#10; &#10;});&#10;" description="Component Unit Test Template" toReformat="false" toShortenFQNames="true">
<variable name="COMPONENT_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
<option name="TypeScript" value="true" />
</context>
</template>
<template name="jts" value="import { async, getTestBed, TestBed } from '@angular/core/testing';&#10;import { Router } from '@angular/router';&#10;import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';&#10;&#10;describe('$SERVICE_NAME$Service', () =&gt; {&#10;&#10; let myService: $SERVICE_NAME$Service;$END$&#10; let injector: TestBed;&#10; let httpMock: HttpTestingController;&#10; let router: Router;&#10;&#10; beforeEach(&#10; async(() =&gt; {&#10; TestBed.configureTestingModule({&#10; imports: [&#10; HttpClientTestingModule,&#10; RouterTestingModule.withRoutes([{path: 'somepath', component: DummyComponent}])&#10; ],&#10; providers: [&#10; $SERVICE_NAME$Service&#10; ]&#10; });&#10; })&#10; );&#10;&#10; beforeEach(() =&gt; {&#10; injector = getTestBed();&#10; myService = injector.get($SERVICE_NAME$Service);&#10; httpMock = injector.get(HttpTestingController);&#10; router = injector.get(Router);&#10; });&#10;&#10; afterAll(() =&gt; {&#10; injector = null;&#10; myService = null;&#10; httpMock = null;&#10; router = null;&#10; });&#10;&#10; afterEach(() =&gt; {&#10; httpMock.verify();&#10; });&#10;&#10;});&#10;" description="Service Unit Test Template" toReformat="false" toShortenFQNames="true">
<variable name="SERVICE_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_SCRIPT" value="true" />
<option name="TypeScript" value="true" />
</context>
</template>
@codesandtags
Copy link
Author

image

You just need to copy and paste the content over this configuration live templates in Intellij. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment