-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uiSrefStatus): emit state/params in events
- Loading branch information
cristHian Gz
committed
Jul 15, 2017
1 parent
4226a19
commit 6ea35f2
Showing
2 changed files
with
67 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Component, DebugElement } from '@angular/core'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { UISref } from '../../src/directives/uiSref'; | ||
import { SrefStatus } from '../../src/directives/uiSrefStatus'; | ||
import { UIRouterModule } from '../../src/uiRouterNgModule'; | ||
|
||
import { Subject } from 'rxjs/Subject'; | ||
|
||
describe('uiSrefStatus', () => { | ||
@Component({ | ||
template: '<a uiSref="foo" (uiSrefStatus)="updated($event)"></a>' | ||
}) | ||
class TestComponent extends Subject<SrefStatus> { | ||
updated(event: SrefStatus) { | ||
this.next(event); | ||
} | ||
} | ||
|
||
let de: DebugElement; | ||
let comp: TestComponent; | ||
let fixture: ComponentFixture<TestComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [TestComponent], | ||
imports: [UIRouterModule.forRoot({ | ||
states: [{ name: 'foo' }], | ||
useHash: true, | ||
})] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestComponent); | ||
comp = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
de = fixture.debugElement.query(By.directive(UISref)); | ||
}); | ||
|
||
describe('when click on `foo` uiSref', () => { | ||
beforeEach(() => { | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should emit a event with identifier equals to `foo`', done => { | ||
comp.subscribe(event => { | ||
expect(event.identifier).toEqual('foo'); | ||
done(); | ||
}); | ||
de.triggerEventHandler('click', {}); | ||
}); | ||
}); | ||
}); |