Created
June 25, 2019 13:51
-
-
Save MatLang/9ad4c07b237ee3ebfa1736a0ac61220b to your computer and use it in GitHub Desktop.
Structural directive testing #testing #directive #structural
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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