-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(directive): add getDirectiveInstance to host
- Loading branch information
1 parent
9b8b256
commit 9b2ffc6
Showing
3 changed files
with
32 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
import { AutoFocusDirective } from './auto-focus.directive'; | ||
import { Component } from '@angular/core'; | ||
import { SpectatorWithHost } from '../lib/src'; | ||
import { createHostComponentFactory } from '../lib/src/host'; | ||
import { AutoFocusDirective } from "./auto-focus.directive"; | ||
import { Component, Directive } from "@angular/core"; | ||
import { SpectatorWithHost } from "../lib/src"; | ||
import { createHostComponentFactory } from "../lib/src/host"; | ||
import { By } from "@angular/platform-browser"; | ||
|
||
@Component({ selector: 'custom-host', template: '' }) | ||
@Component({ selector: "custom-host", template: "" }) | ||
class CustomHostComponent { | ||
isFocused = false; | ||
} | ||
|
||
describe('DatoAutoFocusDirective', function() { | ||
describe("DatoAutoFocusDirective", function() { | ||
let host: SpectatorWithHost<AutoFocusDirective, CustomHostComponent>; | ||
|
||
const createHost = createHostComponentFactory({ | ||
component: AutoFocusDirective, | ||
host: CustomHostComponent | ||
}); | ||
|
||
it('should be focused', () => { | ||
it("should be focused", () => { | ||
host = createHost(`<input datoAutoFocus="true">`); | ||
const instance = host.getDirectiveInstance<AutoFocusDirective>( | ||
AutoFocusDirective | ||
); | ||
expect(host.element).toBeFocused(); | ||
}); | ||
|
||
it('should NOT be focused', () => { | ||
it("should NOT be focused", () => { | ||
host = createHost(`<input [datoAutoFocus]="false">`); | ||
expect(host.element).not.toBeFocused(); | ||
}); | ||
|
||
it('should work with dynamic input', () => { | ||
it("should work with dynamic input", () => { | ||
host = createHost(`<input [datoAutoFocus]="isFocused">`); | ||
expect(host.element).not.toBeFocused(); | ||
host.setHostInput({isFocused: true}); | ||
host.setHostInput({ isFocused: true }); | ||
expect(host.element).toBeFocused(); | ||
}); | ||
}); | ||
}); |
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
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