Fix tests for directives.
This commit is contained in:
parent
f5c69cc574
commit
0343142a38
@ -1,17 +1,33 @@
|
|||||||
// Core imports
|
// Core imports
|
||||||
import { ElementRef, Renderer2 } from '@angular/core';
|
import { Component, DebugElement } from '@angular/core';
|
||||||
|
|
||||||
// Application imports
|
// Application imports
|
||||||
import { PasswordToggleDirective } from '@app/auth/_directives/password-toggle.directive';
|
import { PasswordToggleDirective } from '@app/auth/_directives/password-toggle.directive';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
// tslint:disable-next-line:prefer-const
|
@Component({
|
||||||
let elementRef: ElementRef;
|
template: ` <div>
|
||||||
// tslint:disable-next-line:prefer-const
|
<input type="password" id="password" />
|
||||||
let renderer: Renderer2;
|
<span id="icon" class="fa fa-eye" appPasswordToggle [id]="'password'" [iconId]="'icon'"></span>
|
||||||
|
</div>`,
|
||||||
|
})
|
||||||
|
class TestComponent {}
|
||||||
|
|
||||||
describe('PasswordToggleDirective', () => {
|
describe('PasswordToggleDirective', () => {
|
||||||
it('should create an instance', () => {
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
const directive = new PasswordToggleDirective(elementRef, renderer);
|
let des: DebugElement[];
|
||||||
expect(directive).toBeTruthy();
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.configureTestingModule({
|
||||||
|
declarations: [PasswordToggleDirective, TestComponent],
|
||||||
|
}).createComponent(TestComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
des = fixture.debugElement.queryAll(By.directive(PasswordToggleDirective));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have one element with menu-toggle directive', () => {
|
||||||
|
expect(des.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,21 +1,34 @@
|
|||||||
// Core imports
|
// Core imports
|
||||||
import { ElementRef, Renderer2 } from '@angular/core';
|
import { Component, DebugElement } from '@angular/core';
|
||||||
|
|
||||||
// Application imports
|
// Application imports
|
||||||
import { MenuSelectionDirective } from '@app/shared/_directives/menu-selection.directive';
|
import { MenuSelectionDirective } from '@app/shared/_directives/menu-selection.directive';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: ` <div appMenuSelection>
|
||||||
|
<div id="sidebar"></div>
|
||||||
|
<div id="content"></div>
|
||||||
|
<div id="sidebarCollapse"></div>
|
||||||
|
</div>`,
|
||||||
|
})
|
||||||
|
class TestComponent {}
|
||||||
|
|
||||||
describe('MenuSelectionDirective', () => {
|
describe('MenuSelectionDirective', () => {
|
||||||
// tslint:disable-next-line:prefer-const
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
let elementRef: ElementRef;
|
let des: DebugElement[];
|
||||||
// tslint:disable-next-line:prefer-const
|
|
||||||
let renderer: Renderer2;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// renderer = new
|
fixture = TestBed.configureTestingModule({
|
||||||
|
declarations: [MenuSelectionDirective, TestComponent],
|
||||||
|
}).createComponent(TestComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
des = fixture.debugElement.queryAll(By.directive(MenuSelectionDirective));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should have one element with menu-selection directive', () => {
|
||||||
const directive = new MenuSelectionDirective(elementRef, renderer);
|
expect(des.length).toBe(1);
|
||||||
expect(directive).toBeTruthy();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,18 +1,32 @@
|
|||||||
// Application imports
|
// Application imports
|
||||||
import { MenuToggleDirective } from '@app/shared/_directives/menu-toggle.directive';
|
import { MenuToggleDirective } from '@app/shared/_directives/menu-toggle.directive';
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { Component, DebugElement } from '@angular/core';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: ` <div appMenuToggle>
|
||||||
|
<div id="sidebar"></div>
|
||||||
|
<div id="content"></div>
|
||||||
|
<div id="sidebarCollapse"></div>
|
||||||
|
</div>`,
|
||||||
|
})
|
||||||
|
class TestComponent {}
|
||||||
|
|
||||||
describe('MenuToggleDirective', () => {
|
describe('MenuToggleDirective', () => {
|
||||||
let directive: MenuToggleDirective;
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
|
let des: DebugElement[];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
fixture = TestBed.configureTestingModule({
|
||||||
providers: [MenuToggleDirective],
|
declarations: [MenuToggleDirective, TestComponent],
|
||||||
});
|
}).createComponent(TestComponent);
|
||||||
directive = TestBed.inject(MenuToggleDirective);
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
des = fixture.debugElement.queryAll(By.directive(MenuToggleDirective));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an instance', () => {
|
it('should have one element with menu-toggle directive', () => {
|
||||||
expect(directive).toBeTruthy();
|
expect(des.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user