Skip to content

Instantly share code, notes, and snippets.

@MatLang
Created June 25, 2019 13:51
Show Gist options
  • Save MatLang/9ad4c07b237ee3ebfa1736a0ac61220b to your computer and use it in GitHub Desktop.
Save MatLang/9ad4c07b237ee3ebfa1736a0ac61220b to your computer and use it in GitHub Desktop.
Structural directive testing #testing #directive #structural
import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ShowContactsDirective } from './show-contacts.directive';
import { getElement } from '../../testing';
@Component({
template: `
<div *appShowContacts="true">
<p>This is shown</p>
</div>
<div *appShowContacts="false">
<p>This is hidden</p>
</div>
`
})
class TestComponent {}
describe('Directive: ShowContactsDirective', () => {
let fixture: ComponentFixture<any>;
beforeEach(() => {
fixture = TestBed.configureTestingModule({
declarations: [ShowContactsDirective, TestComponent]
}).createComponent(TestComponent);
fixture.detectChanges();
});
it('should be displayed when the input evaluates to true.', () => {
const element = getElement(fixture);
expect(element.innerText).toContain('This is shown');
});
it('should be hidden when the input evaluates to false.', () => {
const element = getElement(fixture);
expect(element.innerText).not.toContain('This is hidden');
});
afterEach(() => {
fixture = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment