fix: make all tests green with new view engine and JIT

Note that this does not yet include enabling the view engine
by default.

Included refactoring:
- view engine: split namespace of elements / attributes already
  when creating the `NodeDef`
- view engine: when injecting the old `Renderer`, use an implementation
  that is based on `RendererV2`
- view engine: store view queries in the component view, not
  on the host element
This commit is contained in:
Tobias Bosch
2017-02-17 08:56:36 -08:00
committed by Igor Minar
parent 74ce121dba
commit b9f17a9cb2
37 changed files with 527 additions and 300 deletions

View File

@ -11,7 +11,7 @@ import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref
import {Console} from '@angular/core/src/console';
import {ComponentRef} from '@angular/core/src/linker/component_factory';
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, describe, inject, it} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -20,6 +20,10 @@ import {expect} from '@angular/platform-browser/testing/matchers';
import {stringify} from '../../src/facade/lang';
@Component({selector: 'non-existent', template: ''})
class NonExistentComp {
}
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
class HelloRootCmp {
greeting: string;
@ -124,29 +128,32 @@ function bootstrap(
}
export function main() {
let fakeDoc: any /** TODO #9100 */, el: any /** TODO #9100 */, el2: any /** TODO #9100 */,
testProviders: Provider[], lightDom: any /** TODO #9100 */;
let el: any /** TODO #9100 */, el2: any /** TODO #9100 */, testProviders: Provider[],
lightDom: any /** TODO #9100 */;
describe('bootstrap factory method', () => {
let compilerConsole: DummyConsole;
beforeEachProviders(() => { return [Log]; });
beforeEach(() => {
beforeEach(inject([DOCUMENT], (doc: any) => {
destroyPlatform();
compilerConsole = new DummyConsole();
testProviders = [{provide: Console, useValue: compilerConsole}];
fakeDoc = getDOM().createHtmlDocument();
el = getDOM().createElement('hello-app', fakeDoc);
el2 = getDOM().createElement('hello-app-2', fakeDoc);
lightDom = getDOM().createElement('light-dom-el', fakeDoc);
getDOM().appendChild(fakeDoc.body, el);
getDOM().appendChild(fakeDoc.body, el2);
const oldRoots = getDOM().querySelectorAll(doc, 'hello-app,hello-app-2,light-dom-el');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
el = getDOM().createElement('hello-app', doc);
el2 = getDOM().createElement('hello-app-2', doc);
lightDom = getDOM().createElement('light-dom-el', doc);
getDOM().appendChild(doc.body, el);
getDOM().appendChild(doc.body, el2);
getDOM().appendChild(el, lightDom);
getDOM().setText(lightDom, 'loading');
compilerConsole = new DummyConsole();
testProviders =
[{provide: DOCUMENT, useValue: fakeDoc}, {provide: Console, useValue: compilerConsole}];
});
}));
afterEach(destroyPlatform);
@ -167,10 +174,11 @@ export function main() {
const logger = new MockConsole();
const errorHandler = new ErrorHandler(false);
errorHandler._console = logger as any;
bootstrap(HelloRootCmp, [
bootstrap(NonExistentComp, [
{provide: ErrorHandler, useValue: errorHandler}
]).then(null, (reason) => {
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
expect(reason.message)
.toContain('The selector "non-existent" did not match any elements');
async.done();
return null;
});
@ -184,10 +192,10 @@ export function main() {
errorHandler._console = logger as any;
const refPromise =
bootstrap(HelloRootCmp, [{provide: ErrorHandler, useValue: errorHandler}]);
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
refPromise.then(null, (reason: any) => {
expect(reason.message)
.toContain('The selector "hello-app" did not match any elements');
.toContain('The selector "non-existent" did not match any elements');
async.done();
});
}));
@ -199,10 +207,10 @@ export function main() {
errorHandler._console = logger as any;
const refPromise =
bootstrap(HelloRootCmp, [{provide: ErrorHandler, useValue: errorHandler}]);
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
refPromise.then(null, (reason) => {
expect(logger.res.join(''))
.toContain('The selector "hello-app" did not match any elements');
.toContain('The selector "non-existent" did not match any elements');
async.done();
return null;
});

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {afterEach, beforeEach, describe, it} from '@angular/core/testing/testing_internal';
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
import {SpyComponentRef, callNgProfilerTimeChangeDetection} from './spies';