Skip to content

Instantly share code, notes, and snippets.

@kylewhitaker
Last active September 8, 2017 19:38
Show Gist options
  • Save kylewhitaker/3bec3c8a59e8d128e2f321135b66910e to your computer and use it in GitHub Desktop.
Save kylewhitaker/3bec3c8a59e8d128e2f321135b66910e to your computer and use it in GitHub Desktop.
Import only the thing you want to test. Do not import dependencies!
import { SomeComponent } from './some.component.js'; // only import the thing you want to test
describe('SomeComponent:', () => {
let component: SomeComponent;
let mockDepOne: any; // do not import DepOne, 'any' it
let mockDepTwo: any; // do not import DepTwo, 'any' it
let mockDepThree: any; // do not import DepThree, 'any' it
beforeEach(() => {
// mock dependencies
mockDepOne = {
doSomething: jasmine.createSpy('doSomething').and.returnValue('0123456789')
};
mockDepTwo = jasmine.createSpyObj('DepTwo', ['doSomethingElse']);
mockDepThree = jasmine.createSpyObj('DepThree', ['capitalize']);
// initialize component under test with mocked dependencies
component = new SomeComponent(mockDepOne, mockDepTwo, mockDepThree);
});
// ... ...
// ... unit tests here ...
// ... ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment