Is there any way to run a unit test only for a particular component in the angular 4 project?
3 Answers
Add f to describe keyword to focus it. Use fdescribe. This will run only the focused component.
fdescribe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ]
})
.compileComponents();
}));
it('should be created', () => {
expect(component).toBeTruthy();
});
});
Comments
I usually manually change the context in src/test.ts
from this (runs all tests):
const context = require.context('./', true, /\.spec\.ts$/);
to the name of the test file i want to run:
const context = require.context('./', true, /login.service.spec\.ts$/);
This is based on your test file only testing the component.
describeto focus it. Usefdescribe. This will run only the focused component.