fix(router): mount correct component if router outlet was not instantiated and if using a route reuse strategy (#25313) (#25314)

This unsets 'attachRef' on outlet context if no route is to be reused in route activation.

Closes #25313

PR Close #25314
This commit is contained in:
Daniel Wiehl
2018-08-05 15:35:51 +02:00
committed by Igor Minar
parent f2ba55f2fb
commit 8dc2b119fb
5 changed files with 113 additions and 5 deletions

View File

@ -7,8 +7,9 @@
*/
import {ɵglobal as global} from '@angular/core';
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
import {Type, ɵglobal as global} from '@angular/core';
import {ComponentFixture} from '@angular/core/testing';
import {By, ɵgetDOM as getDOM} from '@angular/platform-browser';
@ -79,6 +80,11 @@ export interface NgMatchers<T = any> extends jasmine.Matchers<T> {
*/
toContainError(expected: any): boolean;
/**
* Expect a component of the given type to show.
*/
toContainComponent(expectedComponentType: Type<any>, expectationFailOutput?: any): boolean;
/**
* Invert the matchers.
*/
@ -235,6 +241,29 @@ _global.beforeEach(function() {
};
}
};
},
toContainComponent: function() {
return {
compare: function(actualFixture: any, expectedComponentType: Type<any>) {
const failOutput = arguments[2];
const msgFn = (msg: string): string => [msg, failOutput].filter(Boolean).join(', ');
// verify correct actual type
if (!(actualFixture instanceof ComponentFixture)) {
return {
pass: false,
message: msgFn(
`Expected actual to be of type \'ComponentFixture\' [actual=${actualFixture.constructor.name}]`)
};
}
const found = !!actualFixture.debugElement.query(By.directive(expectedComponentType));
return found ?
{pass: true} :
{pass: false, message: msgFn(`Expected ${expectedComponentType.name} to show`)};
}
};
}
});
});