Skip to content

Commit 2ec4dd4

Browse files
Step one; upcase 'test input' in processInput() method
1 parent 5fa5401 commit 2ec4dd4

8 files changed

Lines changed: 74 additions & 29 deletions

src/app/app.component.css

Whitespace-only changes.

src/app/app.component.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<h1>
2-
{{title}}
3-
</h1>
1+
<component-under-test></component-under-test>

src/app/app.component.spec.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { TestBed, async } from '@angular/core/testing';
22

33
import { AppComponent } from './app.component';
4+
import {ComponentUnderTestModule} from './component-under-test/component-under-test.module';
45

56
describe('AppComponent', () => {
67
beforeEach(async(() => {
78
TestBed.configureTestingModule({
8-
declarations: [
9-
AppComponent
10-
],
9+
declarations: [AppComponent],
10+
imports: [ ComponentUnderTestModule ],
1111
}).compileComponents();
1212
}));
1313

@@ -16,17 +16,4 @@ describe('AppComponent', () => {
1616
const app = fixture.debugElement.componentInstance;
1717
expect(app).toBeTruthy();
1818
}));
19-
20-
it(`should have as title 'app works!'`, async(() => {
21-
const fixture = TestBed.createComponent(AppComponent);
22-
const app = fixture.debugElement.componentInstance;
23-
expect(app.title).toEqual('app works!');
24-
}));
25-
26-
it('should render title in a h1 tag', async(() => {
27-
const fixture = TestBed.createComponent(AppComponent);
28-
fixture.detectChanges();
29-
const compiled = fixture.debugElement.nativeElement;
30-
expect(compiled.querySelector('h1').textContent).toContain('app works!');
31-
}));
3219
});

src/app/app.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-root',
5-
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css']
5+
templateUrl: './app.component.html'
76
})
87
export class AppComponent {
9-
title = 'app works!';
108
}

src/app/app.module.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
3-
import { FormsModule } from '@angular/forms';
4-
import { HttpModule } from '@angular/http';
1+
import {BrowserModule} from '@angular/platform-browser';
2+
import {NgModule} from '@angular/core';
3+
import {FormsModule} from '@angular/forms';
4+
import {HttpModule} from '@angular/http';
55

6-
import { AppComponent } from './app.component';
6+
import {AppComponent} from './app.component';
7+
import {ComponentUnderTestModule} from './component-under-test/component-under-test.module';
78

89
@NgModule({
910
declarations: [
@@ -12,9 +13,11 @@ import { AppComponent } from './app.component';
1213
imports: [
1314
BrowserModule,
1415
FormsModule,
15-
HttpModule
16+
HttpModule,
17+
ComponentUnderTestModule
1618
],
1719
providers: [],
1820
bootstrap: [AppComponent]
1921
})
20-
export class AppModule { }
22+
export class AppModule {
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {ComponentUnderTestComponent} from './component-under-test.component';
4+
5+
describe('ComponentUnderTestComponent', () => {
6+
let component: ComponentUnderTestComponent;
7+
let fixture: ComponentFixture<ComponentUnderTestComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ComponentUnderTestComponent]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ComponentUnderTestComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should be created', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
26+
it('should show TEST INPUT', () => {
27+
component.input = 'test input';
28+
component.processInput();
29+
fixture.detectChanges();
30+
expect(fixture.nativeElement.querySelector('div').innerText).toEqual('TEST INPUT');
31+
});
32+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
import {Input} from '@angular/core';
3+
4+
@Component({
5+
selector: 'component-under-test',
6+
template: '<div>{{ input }}</div>'
7+
})
8+
export class ComponentUnderTestComponent{
9+
10+
@Input() input;
11+
12+
processInput(): void {
13+
this.input = this.input.toUpperCase();
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import {ComponentUnderTestComponent} from './component-under-test.component';
4+
5+
@NgModule({
6+
imports: [
7+
CommonModule
8+
],
9+
declarations: [ComponentUnderTestComponent],
10+
exports: [ComponentUnderTestComponent]
11+
})
12+
export class ComponentUnderTestModule { }

0 commit comments

Comments
 (0)