chore: fix tests

This commit is contained in:
Roman Hotsiy 2017-03-15 17:51:46 +02:00
parent 631dfc17dc
commit abae4c03c3
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
5 changed files with 22 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import {
Injectable, Injectable,
ComponentFactory, ComponentFactory,
ComponentRef, ComponentRef,
ViewContainerRef, ViewContainerRef
} from '@angular/core'; } from '@angular/core';
@Injectable() @Injectable()
@ -19,7 +19,6 @@ export class ContentProjector {
for (let i=0; i < projectedNodesOrComponents.length; i++) { for (let i=0; i < projectedNodesOrComponents.length; i++) {
let nodeOrCompRef = projectedNodesOrComponents[i]; let nodeOrCompRef = projectedNodesOrComponents[i];
if (nodeOrCompRef instanceof ComponentRef) { if (nodeOrCompRef instanceof ComponentRef) {
//nodeOrCompRef.changeDetectorRef.detectChanges();
projectedNodes.push(nodeOrCompRef.location.nativeElement); projectedNodes.push(nodeOrCompRef.location.nativeElement);
componentRefs.push(nodeOrCompRef); componentRefs.push(nodeOrCompRef);
} else { } else {
@ -29,13 +28,13 @@ export class ContentProjector {
let parentCompRef = parentView.createComponent(componentFactory, null, contextInjector, [projectedNodes]); let parentCompRef = parentView.createComponent(componentFactory, null, contextInjector, [projectedNodes]);
// using private property to get AppElement instance // using private property to get view instance
let viewContainer = (<any>parentView)._view; let viewContainer = (<any>parentView)._view;
let viewData = (<any>parentView)._data; let viewData = (<any>parentView)._data;
viewData.embeddedViews = viewData.embeddedViews || []; viewData.embeddedViews = viewData.embeddedViews || [];
for (let i=0; i < componentRefs.length; i++) { for (let i=0; i < componentRefs.length; i++) {
let compRef = componentRefs[i]; let compRef = componentRefs[i];
// attach view to viewContainer change detector // attach view to containter change detector
viewData.embeddedViews.push((<any>compRef.hostView)._view); viewData.embeddedViews.push((<any>compRef.hostView)._view);
(<any>compRef.hostView).attachToViewContainerRef(viewContainer); (<any>compRef.hostView).attachToViewContainerRef(viewContainer);
} }

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { getDOM } from '@angular/platform-browser/src/dom/dom_adapter';
/** Gets a child DebugElement by tag name. */ /** Gets a child DebugElement by tag name. */
export function getChildDebugElement(parent, tagName) { export function getChildDebugElement(parent, tagName) {
@ -20,7 +19,13 @@ export function getChildDebugElementAll(parent, tagName) {
export function mouseclick( element ) { export function mouseclick( element ) {
// create a mouse click event // create a mouse click event
var dispatchedEvent = getDOM().createMouseEvent('click'); var dispatchedEvent
try {
dispatchedEvent = new MouseEvent('click', true);
} catch (e) {
dispatchedEvent = document.createEvent('MouseEvent');
dispatchedEvent.initEvent('click', true, false);
}
// send click to element // send click to element
getDOM().dispatchEvent(element, dispatchedEvent); element.dispatchEvent(dispatchedEvent);
} }

View File

@ -20,9 +20,10 @@ require('../lib/vendor');
var TestBed = require('@angular/core/testing').TestBed; var TestBed = require('@angular/core/testing').TestBed;
var ErrorHandler = require('@angular/core').ErrorHandler; var ErrorHandler = require('@angular/core').ErrorHandler;
var forwardRef = require('@angular/core').forwardRef;
var BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; var BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
var platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting; var platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting;
var BrowserAnimationsModule = require('@angular/platform-browser/animations').BrowserAnimationsModule;
var SpecManager = require('../lib/utils/spec-manager').SpecManager; var SpecManager = require('../lib/utils/spec-manager').SpecManager;
var services = require('../lib/services/index'); var services = require('../lib/services/index');
var REDOC_PIPES = require('../lib/utils/pipes').REDOC_PIPES; var REDOC_PIPES = require('../lib/utils/pipes').REDOC_PIPES;
@ -38,6 +39,7 @@ TestBed.initTestEnvironment(
beforeEach(function() { beforeEach(function() {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [BrowserAnimationsModule],
providers: [ providers: [
SpecManager, SpecManager,
services.AppStateService, services.AppStateService,
@ -51,7 +53,7 @@ beforeEach(function() {
services.Marker, services.Marker,
services.SearchService, services.SearchService,
{ provide: sharedComponents.LazyTasksService, useClass: sharedComponents.LazyTasksServiceSync }, { provide: sharedComponents.LazyTasksService, useClass: sharedComponents.LazyTasksServiceSync },
{ provide: ErrorHandler, useClass: services.CustomErrorHandler }, //{ provide: ErrorHandler, useClass: forwardRef(function() {return services.CustomErrorHandler}) },
{ provide: services.COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': components.SecurityDefinitions }} { provide: services.COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': components.SecurityDefinitions }}
], ],
declarations: [REDOC_PIPES, REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES] declarations: [REDOC_PIPES, REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES]

View File

@ -9,10 +9,12 @@
"pretty": true, "pretty": true,
"moduleResolution": "node", "moduleResolution": "node",
"types": [ "types": [
"core-js",
"jasmine", "jasmine",
"should", "should",
"requirejs" "webpack"
],
"lib": [
"DOM", "ES2016", "DOM.Iterable"
], ],
"noEmitHelpers": true "noEmitHelpers": true
}, },

View File

@ -1,4 +1,7 @@
{ {
"linterOptions": {
"typeCheck": true
},
"rulesDirectory": ["node_modules/codelyzer"], "rulesDirectory": ["node_modules/codelyzer"],
"rules": { "rules": {
"class-name": true, "class-name": true,
@ -42,7 +45,6 @@
"no-input-rename": true, "no-input-rename": true,
"no-output-rename": true, "no-output-rename": true,
"pipe-naming": [true, "camelCase"], "pipe-naming": [true, "camelCase"],
"import-destructuring-spacing": true,
"use-life-cycle-interface": true, "use-life-cycle-interface": true,
"use-pipe-transform-interface": true, "use-pipe-transform-interface": true,
"templates-use-public": true, "templates-use-public": true,