Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wescopeland/4b6fcec8311592915ae195421278fc15 to your computer and use it in GitHub Desktop.
Save wescopeland/4b6fcec8311592915ae195421278fc15 to your computer and use it in GitHub Desktop.
presentational-button.component.spec.ts
import { Spectator, createTestComponentFactory } from '@netbasal/spectator/jest';
import { PresentationalButtonComponent as PBComponent } from './presentational-button.component';
describe('Component: PresentationalButtonComponent', () => {
let spectator: Spectator<PBComponent>;
const createComponent = createTestComponentFactory<PBComponent>({
component: PBComponent
});
beforeEach(() => {
spectator = createComponent();
});
it('exists', () => {
expect(spectator.component).toBeDefined();
});
// JSDOM
it('renders a button with a default label if no label is given', () => {
expect(spectator.query('button')).toHaveText('Submit');
});
// JSDOM
it('renders a button with an input label if one is given', () => {
spectator.component.buttonLabel = 'Mock Label';
spectator.detectChanges();
expect(spectator.query('button')).toHaveText('Mock Label');
});
// Component Class
it('can emit a message', () => {
const pressEmitSpy = spyOn(spectator.component.press, 'emit');
spectator.component.handleButtonClick();
expect(pressEmitSpy).toHaveBeenCalledWith('Submit was pressed!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment