Extra Options

There are times when we need more control over the things we require in our tests. For example, your component may depend on some other module or providers. Let's see how we can do it with Spectator:

import { AccordionComponent } from './accordion.component';
import { Spectator, createTestComponentFactory } from '@netbasal/spectator';

describe('AccordionComponent', () => {

  let spectator: Spectator<AccordionComponent>;

  const createComponent = createTestComponentFactory({
     component: ButtonComponent,
     imports: [OtherModule],
     providers: [AccordionGroup, AccordionContent, AccordionDirective]
  });

  it('should ...', () => {
    spectator = createComponent();
    expect(spectator.query('button')).toHaveClass('success');
  });

});

Animations

By default, Spectator uses the NoopAnimationsModule by Angular to disable animations. If you still want animations, you can pass the following parameter:

 const createComponent = createTestComponentFactory({
     component: ButtonComponent,
     disableAnimations: false
});

Shallow

By default, Spectator does NOT use the NO_ERRORS_SCHEMA by Angular to disable errors. If you want to use it, you can pass the following parameter:

 const createComponent = createTestComponentFactory({
     component: ButtonComponent,
     shallow: true
});

results matching ""

    No results matching ""