Last active
September 8, 2017 19:38
-
-
Save kylewhitaker/3bec3c8a59e8d128e2f321135b66910e to your computer and use it in GitHub Desktop.
Import only the thing you want to test. Do not import dependencies!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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