1

Is there any way to run a unit test only for a particular component in the angular 4 project?

1
  • Add f to describe to focus it. Use fdescribe. This will run only the focused component. Commented Jun 4, 2018 at 9:46

3 Answers 3

1

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();
  });
});
Sign up to request clarification or add additional context in comments.

Comments

1

if you want to run one test then use fit. if set of tests then use fdescribe

describe('sample', () => {


  fit('should be created', () => {
    expect(component).toBeTruthy();
  });
});

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.