"Can't resolve all parameters for MdDialogRef: (?)" Error when testing NG2 Material Dialog component
<p>I have a login component as follows: </p>

<pre><code>import { Component, OnInit } from '@angular/core';
import { MdDialogRef } from '@angular/material';

import { AuthService } from '../../core/services/auth.service';

@Component({
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginDialogComponent implements OnInit {

  model: {
    email: string,
    password: string
  };
  error;

  constructor(
    private authService: AuthService,
    private dialogRef: MdDialogRef&lt;LoginDialogComponent&gt;
  ) { }

  ngOnInit() {
    this.model = {
      email: '',
      password: ''
    };
  }

  signin() {
    this.error = null;
    this.authService.login(this.model.email, this.model.password).subscribe(data =&gt; {
      this.dialogRef.close(data);
    }, err =&gt; {
      this.error = err.json();
    });
  }

}
</code></pre>

<p>And I have a test spec for this component as follows:</p>

<pre><code>import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MdDialogRef, OverlayRef  } from '@angular/material';

import { AuthService } from '../../core/services/auth.service';
import { LoginDialogComponent } from './login.component';

describe('Component: Login', () =&gt; {

    let component: LoginDialogComponent;
    let fixture: ComponentFixture&lt;LoginDialogComponent&gt;;

    beforeEach(async(() =&gt; {
        TestBed.configureTestingModule({
            declarations: [
                LoginDialogComponent
            ],
            imports: [],
            providers: [
                AuthService,
                MdDialogRef,
                OverlayRef
            ]
        })
            .compileComponents();
    }));

    beforeEach(() =&gt; {
        fixture = TestBed.createComponent(LoginDialogComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    it('should create', () =&gt; {
        expect(component).toBeTruthy();
    });
});
</code></pre>

<p>I've tried a million different things, and no matter what I do, I get the following error:</p>

<blockquote>
  <p>Can't resolve all parameters for MdDialogRef: (?)</p>
</blockquote>

<p>Here's the code for MdDialogRef, which only has 1 parameter, OverlayRef. What am I missing?</p>

<pre><code>import { OverlayRef } from '../core';
import { Observable } from 'rxjs/Observable';
/**
 * Reference to a dialog opened via the MdDialog service.
 */
export declare class MdDialogRef&lt;T&gt; {
    private _overlayRef;
    /** The instance of component opened into the dialog. */
    componentInstance: T;
    /** Subject for notifying the user that the dialog has finished closing. */
    private _afterClosed;
    constructor(_overlayRef: OverlayRef);
    /**
     * Close the dialog.
     * @param dialogResult Optional result to return to the dialog opener.
     */
    close(dialogResult?: any): void;
    /** Gets an observable that is notified when the dialog is finished closing. */
    afterClosed(): Observable&lt;any&gt;;
}
</code></pre>

<p><strong>EDIT:</strong> taking a clue from @Ryan's comment, I tried removing the MdDialogRef provider entirely and got the following error:</p>

<blockquote>
  <p>Can't resolve all parameters for OverlayRef: (?, ?, ?)</p>
</blockquote>

<p>This leads me to believe that the problem is actually w/MdDialogRef trying to resolve OverlayRef, not w/MdDialogRef itself.</p>

<p><strong>WORKING EXAMPLE</strong> The code below is the actual working code, per Yurzui's suggestion.</p>

<pre><code>    /* tslint:disable:no-unused-variable */

import { NgModule } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MaterialModule, MdDialogModule, MdToolbarModule, MdDialog, MdDialogRef } from '@angular/material';

import { CoreModule } from '../../core/core.module';
import { LoginDialogComponent } from './login.component';

@NgModule({
    declarations: [
        LoginDialogComponent
    ],
    entryComponents: [
        LoginDialogComponent
    ],
    exports: [
        LoginDialogComponent
    ],
    imports: [
        CommonModule,
        CoreModule,
        FormsModule,
        MaterialModule.forRoot(),
        MdDialogModule.forRoot(),
        MdToolbarModule.forRoot()
    ]
})
class LoginDialogSpecModule { }

describe('Component: Login Dialog', () =&gt; {
    let component: LoginDialogComponent;
    let dialog: MdDialog;

    beforeEach(() =&gt; {
        TestBed.configureTestingModule({
            imports: [
                LoginDialogSpecModule
            ]
        });
    });

    beforeEach(() =&gt; {
        dialog = TestBed.get(MdDialog);
        let dialogRef = dialog.open(LoginDialogComponent);
        component = dialogRef.componentInstance;
    });

    it('should create', () =&gt; {
        expect(component).toBeTruthy();
    });
});
</code></pre>