Created
January 27, 2017 05:52
-
-
Save renevall/24e980c2a8442d9daaf187debd2d4369 to your computer and use it in GitHub Desktop.
Testing Dialog having it in a shared module
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
<h1 md-dialog-title>Would you like to order pizza?</h1> | |
<md-dialog-actions> | |
<button (click)="dialogRef.close('yes')">Yes</button> | |
<button md-dialog-close>No</button> | |
</md-dialog-actions> |
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
import { Component, OnInit } from '@angular/core'; | |
import { MdDialogRef } from '@angular/material'; | |
@Component({ | |
selector: 'app-confirm-dialog', | |
templateUrl: './confirm-dialog.component.html', | |
styleUrls: ['./confirm-dialog.component.scss'] | |
}) | |
export class ConfirmDialogComponent implements OnInit { | |
constructor(public dialogRef: MdDialogRef<ConfirmDialogComponent>) { } | |
ngOnInit() { | |
} | |
} |
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
/* tslint:disable:no-unused-variable */ | |
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; | |
import { By, BrowserModule } from '@angular/platform-browser'; | |
import { DebugElement, NgModule } from '@angular/core'; | |
import { MdDialogModule, MdDialog, OverlayContainer, MaterialModule } from '@angular/material'; | |
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; | |
import { ConfirmDialogComponent } from './confirm-dialog.component'; | |
import { SharedModule } from '../shared.module'; | |
@NgModule({ | |
declarations: [ConfirmDialogComponent], | |
exports: [ConfirmDialogComponent], | |
entryComponents: [ConfirmDialogComponent], | |
imports: [MdDialogModule], | |
}) | |
class DialogTestModule { } | |
describe('ConfirmDialogComponent', () => { | |
let component: ConfirmDialogComponent; | |
let dialog: MdDialog; | |
let overlayContainerElement: HTMLElement; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
imports: [DialogTestModule, MdDialogModule.forRoot()], | |
providers: [ | |
{ | |
provide: OverlayContainer, useFactory: () => { | |
overlayContainerElement = document.createElement('div'); | |
return { getContainerElement: () => overlayContainerElement }; | |
} | |
} | |
], | |
}) | |
.compileComponents(); | |
})); | |
beforeEach(() => { | |
dialog = TestBed.get(MdDialog); | |
let dialogRef = dialog.open(ConfirmDialogComponent); | |
component = dialogRef.componentInstance; | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
}); |
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
import { AuthService } from './shared/auth.service'; | |
import { AlertService } from './shared/alert.service'; | |
import { ToolbarService } from './shared/toolbar.service'; | |
// Material | |
import { MaterialModule } from '@angular/material'; | |
// Layout | |
import { FlexLayoutModule } from '@angular/flex-layout'; | |
// Shared | |
import { SharedModule } from './shared/shared.module'; | |
// Auth | |
import { AuthModule } from './auth/auth.module'; | |
// Admin | |
import { AdminModule } from './admin/admin.module'; | |
// Covalent | |
import { CovalentDataTableModule } from '@covalent/core'; | |
import 'hammerjs'; | |
@NgModule({ | |
declarations: [ | |
AppComponent, | |
], | |
imports: [ | |
BrowserModule, | |
FormsModule, | |
HttpModule, | |
MaterialModule.forRoot(), | |
FlexLayoutModule.forRoot(), | |
SharedModule, | |
routing, | |
HomeModule, | |
LawModule, | |
AuthModule, | |
AdminModule, | |
CovalentDataTableModule.forRoot(), | |
], | |
providers: [MenuService, AlertService, AuthService, ToolbarService], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MaterialModule.forRoot() complained for me ("forRoot doesn't exist... something, something"). It worked when skipped any mention of it in main.module.