Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 5c89c7c

Browse files
committed
Fix broken unit tests
1 parent 5c86f57 commit 5c89c7c

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/app/shared/example-viewer/example-viewer.spec.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import {ReactiveFormsModule} from '@angular/forms';
2-
import {async, inject, ComponentFixture, TestBed} from '@angular/core/testing';
3-
import {MockBackend} from '@angular/http/testing';
4-
import {Response, ResponseOptions} from '@angular/http';
5-
import {By} from '@angular/platform-browser';
6-
7-
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
8-
import {ExampleViewer} from './example-viewer';
9-
import {DocsAppTestingModule} from '../../testing/testing-module';
10-
import {DocViewerModule} from '../doc-viewer/doc-viewer-module';
11-
import {FormsModule} from '@angular/forms';
12-
import {NgModule} from '@angular/core';
131
import {CommonModule} from '@angular/common';
14-
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
2+
import {NgModule} from '@angular/core';
3+
import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing';
4+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
5+
import {Response, ResponseOptions} from '@angular/http';
6+
import {MockBackend} from '@angular/http/testing';
157
import {
168
MatAutocompleteModule,
179
MatInputModule,
18-
MatSlideToggleModule
10+
MatSlideToggleModule,
11+
MatSnackBar,
1912
} from '@angular/material';
13+
14+
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
15+
import {By} from '@angular/platform-browser';
16+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
17+
import {DocsAppTestingModule} from '../../testing/testing-module';
2018
import {CopierService} from '../copier/copier.service';
21-
import {MatSnackBar} from '@angular/material';
19+
import {DocViewerModule} from '../doc-viewer/doc-viewer-module';
20+
import {ExampleViewer} from './example-viewer';
2221

2322
const exampleKey = 'autocomplete-overview';
2423

@@ -51,30 +50,30 @@ describe('ExampleViewer', () => {
5150
component = fixture.componentInstance;
5251
});
5352

54-
it('should toggle showSource boolean', () => {
53+
it('should toggle showSource boolean', async(() => {
5554
fixture.detectChanges();
5655
expect(component.showSource).toBe(false);
5756
component.toggleSourceView();
5857
expect(component.showSource).toBe(true);
59-
});
58+
}));
6059

61-
it('should set and return example properly', () => {
60+
it('should set and return example properly', async(() => {
6261
component.example = exampleKey;
6362
fixture.detectChanges();
6463
const data = component.exampleData;
6564
// TODO(jelbourn): remove `as any` once LiveExample is updated to have optional members.
6665
expect(data).toEqual(EXAMPLE_COMPONENTS[exampleKey] as any);
67-
});
66+
}));
6867

69-
it('should log message about missing example', () => {
68+
it('should log message about missing example', async(() => {
7069
spyOn(console, 'log');
7170
component.example = 'foobar';
7271
fixture.detectChanges();
7372
expect(console.log).toHaveBeenCalled();
7473
expect(console.log).toHaveBeenCalledWith('MISSING EXAMPLE: ', 'foobar');
75-
});
74+
}));
7675

77-
it('should return assets path for example based on extension', () => {
76+
it('should return assets path for example based on extension', async(() => {
7877
// set example
7978
component.example = exampleKey;
8079
fixture.detectChanges();
@@ -87,7 +86,7 @@ describe('ExampleViewer', () => {
8786
const actual = component.exampleFileUrl(ext);
8887
expect(actual).toEqual(expected);
8988
});
90-
});
89+
}));
9190

9291
describe('copy button', () => {
9392
let button: HTMLElement;
@@ -103,33 +102,33 @@ describe('ExampleViewer', () => {
103102
button = btnDe ? btnDe.nativeElement : null;
104103
});
105104

106-
it('should call copier service when clicked', () => {
105+
it('should call copier service when clicked', (() => {
107106
const copierService: CopierService = TestBed.get(CopierService);
108107
const spy = spyOn(copierService, 'copyText');
109108
expect(spy.calls.count()).toBe(0, 'before click');
110109
button.click();
111110
expect(spy.calls.count()).toBe(1, 'after click');
112111
expect(spy.calls.argsFor(0)[0]).toBe('my docs page', 'click content');
113-
});
112+
}));
114113

115-
it('should display a message when copy succeeds', () => {
114+
it('should display a message when copy succeeds', (() => {
116115
const snackBar: MatSnackBar = TestBed.get(MatSnackBar);
117116
const copierService: CopierService = TestBed.get(CopierService);
118117
spyOn(snackBar, 'open');
119118
spyOn(copierService, 'copyText').and.returnValue(true);
120119
button.click();
121120
expect(snackBar.open).toHaveBeenCalledWith('Code copied', '', {duration: 2500});
122-
});
121+
}));
123122

124-
it('should display an error when copy fails', () => {
123+
it('should display an error when copy fails', (() => {
125124
const snackBar: MatSnackBar = TestBed.get(MatSnackBar);
126125
const copierService: CopierService = TestBed.get(CopierService);
127126
spyOn(snackBar, 'open');
128127
spyOn(copierService, 'copyText').and.returnValue(false);
129128
button.click();
130129
expect(snackBar.open)
131130
.toHaveBeenCalledWith('Copy failed. Please try again!', '', {duration: 2500});
132-
});
131+
}));
133132
});
134133

135134
});

src/app/shared/stackblitz/stackblitz-button.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ export class StackblitzButton {
2525
set example(example: string) {
2626
const exampleData = new ExampleData(example);
2727

28-
this.stackblitzWriter.constructStackblitzForm(exampleData).then(stackblitzForm => {
29-
this.stackblitzForm = stackblitzForm;
30-
this.isDisabled = false;
31-
});
28+
if (example) {
29+
this.stackblitzWriter.constructStackblitzForm(exampleData).then(stackblitzForm => {
30+
this.stackblitzForm = stackblitzForm;
31+
this.isDisabled = false;
32+
});
33+
} else {
34+
this.isDisabled = true;
35+
}
3236
}
3337

3438
constructor(private stackblitzWriter: StackblitzWriter) {}

0 commit comments

Comments
 (0)