Skip to content

Commit 4accdba

Browse files
committed
Add failing test for clicking on nested links (reproduces angular-ui#2962)
1 parent a0688ae commit 4accdba

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/ng1/stateDirectivesSpec.js

+44
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,50 @@ describe('uiStateRef', function() {
271271
}));
272272
});
273273

274+
describe('nested links', function() {
275+
var inner, outer;
276+
beforeEach(inject(function($rootScope, $compile, $timeout, $document) {
277+
el = angular.element('<div id="outer" ui-sref="contacts">Outer <a ui-sref="contacts.item({ id: 1 })">Inner</a></div>');
278+
$compile(el)($rootScope);
279+
$rootScope.$digest();
280+
281+
inner = el.find('a');
282+
outer = el;
283+
$document[0].body.appendChild(el[0]);
284+
285+
286+
timeoutFlush = function () {
287+
try {
288+
$timeout.flush();
289+
} catch (e) {
290+
// Angular 1.0.8 throws 'No deferred tasks to be flushed' if there is nothing in queue.
291+
// Behave as Angular >=1.1.5 and do nothing in such case.
292+
}
293+
}
294+
}));
295+
296+
afterEach(inject(function($document) {
297+
$document[0].body.removeChild(el[0]);
298+
}));
299+
300+
it('should navigate to the inner sref when clicking on the inner link', inject(function($q, $state, $stateParams) {
301+
triggerClick(inner);
302+
timeoutFlush();
303+
$q.flush();
304+
305+
expect($state.current.name).toEqual('contacts.item');
306+
expect(obj($stateParams)).toEqualData({ id: 1 });
307+
}));
308+
309+
it('should navigate to the outer sref when clicking on the outer element', inject(function($q, $state) {
310+
triggerClick(outer);
311+
timeoutFlush();
312+
$q.flush();
313+
314+
expect($state.current.name).toEqual('contacts');
315+
}));
316+
});
317+
274318
describe('links in html5 mode', function() {
275319
beforeEach(function() {
276320
_locationProvider.html5Mode(true);

0 commit comments

Comments
 (0)