VS Code snippets that will make your testing life easier.
Snippet | Description |
---|---|
desc |
Generates an a describe function |
giv |
Generates an a Given function |
when |
Generates an a When function |
then |
Generates an a Then function |
testcase |
describe with Given and Then |
descwhen |
describe with When |
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 |
Output:
describe('<Your Description>', () => {
});
Output:
Given(() => {
});
Output:
When(() => {
});
Output:
Then(() => {
});
Output:
describe('GIVEN: <--Your Given Description-->', () => {
Given(() => {
});
Then('<Your THEN description>', () => {
});
});
Output:
describe('METHOD: <Method Name>', () => {
When(() => {
serviceUnderTest.<Method Name>()
});
});
⚠ 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-->
});
});
});
});
⚠ 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-->
});
});
});
});
⚠ 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-->', () => {
});
});
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);
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,
Output:
<--myMethod-->() {
throw new Error('Method not implemented.');
}
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 🙏
Be kind to each other and please read our code of conduct.
MIT