HiRez.io Testing Snippets
VS Code snippets that will make your testing life easier.
 
 
 

Want to learn more about how to use these snippets correctly?
Available Snippets:
| Snippet | Description | 
| desc | Generates an a describefunction | 
| giv | Generates an a Givenfunction | 
| when | Generates an a Whenfunction | 
| then | Generates an a Thenfunction | 
| testcase | describewithGivenandThen | 
| descwhen | describewithWhen | 
| acomptest | Generates an Angular Component test | 
| aservtest | Generates an Angular Service test | 
| ngtestbase | Generates a base for an Angular micro test | 
| addSpy | Adds a jasmine/jest auto spy boilerplate code | 
| addDep | shortest way to add a private typed dependency to a class constructor | 
| methodplaceholder | Generates an empty method that throws an "unimplemented" error | 
Snippets Usage
SNIPPET: desc
Output:
describe('<Your Description>', () => {
  
});
SNIPPET: giv
Output:
Given(() => {
  
});
SNIPPET: when
Output:
When(() => {
  
});
SNIPPET: then
Output:
Then(() => {
  
});
SNIPPET: testcase
Output:
describe('GIVEN: <--Your Given Description-->', () => {
  
  Given(() => {
  
  });
  
  Then('<Your THEN description>', () => {
  
  });
});
SNIPPET: descwhen
Output:
describe('METHOD: <Method Name>', () => {
  
  When(() => {
    serviceUnderTest.<Method Name>()
  });
  
});
SNIPPET: acomptest
⚠ INSTRUCTIONS:
- Choose between "jasmine" or "jest"
- Hit "tab" to jump between variables
Output:
import { TestBed } from '@angular/core/testing';
import { Spy, provideAutoSpy } from '<--Your Testing Framework-->-auto-spies';
describe('<--Your Component Type-->', () => {
  let componentUnderTest: <--Your Component Type-->;
  Given(() => {
    TestBed.configureTestingModule({
      providers: [<--Your Component Type-->]
    });
    componentUnderTest = TestBed.inject(<--Your Component Type-->);
  });
  describe('METHOD: <--Method Name-->', () => {
    When(() => {
      componentUnderTest.<--Method Name-->();
    });
    describe('GIVEN <--Your Given Description-->', () => {
      Given(() => {
        // <--Your Given Description-->
        
      });
      Then('<--Your Then Description-->', () => {
        // <--Your Then Description-->
      });
    });
  });
});
SNIPPET: aservtest
⚠ INSTRUCTIONS:
- Choose between "jasmine" or "jest"
- Hit "tab" to jump between variables
Output:
import { TestBed } from '@angular/core/testing';
import { Spy, provideAutoSpy } from '<--Your Testing Framework-->-auto-spies';
describe('<--Your Service Type-->', () => {
  let serviceUnderTest: <--Your Service Type-->;
  let actualResult: any;
  Given(() => {
    TestBed.configureTestingModule({
      providers: [<--Your Service Type-->]
    });
    serviceUnderTest = TestBed.inject(<--Your Service Type-->);
    actualResult = undefined;
  });
  describe('METHOD: <--Method Name-->', () => {
    When(() => {
      serviceUnderTest.<--Method Name-->();
    });
    describe('GIVEN <--Your Given Description-->', () => {
      Given(() => {
        // <--Your Given Description-->
        
      });
      Then('<--Your Then Description-->', () => {
        // <--Your Then Description-->
      });
    });
  });
});
SNIPPET: ngtestbase
⚠ INSTRUCTIONS:
- Choose between "jasmine" or "jest"
- Hit "tab" to jump between variables
- Choose between "component", "service", "directive" or "pipe"
Output:
import { TestBed } from '@angular/core/testing';
import { Spy, provideAutoSpy } from '<--Your Testing Framework-->-auto-spies';
describe('<--Type To Test-->', () => {
  let <--Angular Type Choice-->UnderTest: <--Type To Test-->;
  let actualResult: any;
  Given(() => {
    TestBed.configureTestingModule({
      providers: [<--Type To Test-->]
    });
    <--Angular Type Choice-->UnderTest = TestBed.inject(<--Type To Test-->);
    actualResult = undefined;
  });
  describe('METHOD: <--Method Name-->', () => {
  });
});
SNIPPET: addSpy
Makes adding an "auto spy" very easy.
⚠ INSTRUCTIONS:
- Write / paste your class type
- Hit "tab" to turn the variable to camelCase ("lowercase"s the first letter)
- Cut and paste each line to its appropriate place
Output:
// This goes in your first "Describe":
let myServiceTypeSpy: Spy<MyServiceType>;
// This goes in your TestBed's "providers" array:
provideAutoSpy(MyServiceType),
// This goes in your first Given:
MyServiceTypeSpy = TestBed.inject<any>(MyServiceType);
SNIPPET: addDep
Makes adding a class constructor dependency very easy.
⚠ INSTRUCTIONS:
- Write or paste your class type
- Hit "tab" to turn the variable to camelCase ("lowercase"s the first letter)
Output:
private myServiceType: MyServiceType,
SNIPPET: methodplaceholder
Output:
<--myMethod-->() {
  throw new Error('Method not implemented.');
}
Contributing
Want to contribute? Yayy! 🎉
Please read and follow our Contributing Guidelines to learn what are the right steps to take before contributing your time, effort and code.
Thanks 🙏
Code Of Conduct
Be kind to each other and please read our code of conduct.
License
MIT