Skip to content

Instantly share code, notes, and snippets.

@kylewhitaker
Created September 8, 2017 19:34
Show Gist options
  • Save kylewhitaker/5fe008c6bf4ab666dc2cfa49a932ff93 to your computer and use it in GitHub Desktop.
Save kylewhitaker/5fe008c6bf4ab666dc2cfa49a932ff93 to your computer and use it in GitHub Desktop.
Step #1 to writing a great unit test file is scaffolding!
describe('SomeComponent:', () => {
describe('someMethod', () => {
describe('true', () => {
it('should call depOne.doSomething', () => {
});
it('should return string \'eggs for breakfast\'', () => {
});
});
describe('false', () => {
it('should call depTwo.doSomethingElse', () => {
});
it('should return string \'steak for dinner\'', () => {
});
});
});
describe('returnSomeObservable', () => {
it('should return a string Observable of \'test\'', () => {
});
});
describe('subscribeAndDoSomething', () => {
it('should call depThree.capitalize on the value \'jabroni\' emitted', () => {
});
});
});
import { Observable } from 'rxjs';
import { DepOne, DepTwo, DepThree } from './dependencies';
export class SomeComponent {
constructor(
private depOne: DepOne,
private depTwo: DepTwo,
private depThree: DepThree
) { }
someMethod(someCondition: boolean): string {
if (someCondition) {
this.depOne.doSomething();
return 'eggs for breakfast';
} else {
this.depTwo.doSomethingElse();
return 'steak for dinner';
}
}
returnSomeObservable(): Observable<string> {
return Observable.of('test');
}
subscribeAndDoSomething(): void {
Observable.of('jabroni').subscribe((value) => {
this.depThree.capitalize(value);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment