Created
May 4, 2018 19:53
-
-
Save victormejia/a87abcd9960438bcd5ea38403c999b4e to your computer and use it in GitHub Desktop.
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 { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { HackerStatusComponent } from './hacker-status.component'; | |
import { Component } from '@angular/core'; | |
import { By } from '@angular/platform-browser'; | |
@Component({ | |
template: | |
'<vm-hacker-status [status]="appStatus"></vm-hacker-status>' | |
}) | |
class TestHostComponent { | |
appStatus: string; | |
} | |
describe('HackerStatusComponent', () => { | |
let testHost: TestHostComponent; | |
let fixture: ComponentFixture<TestHostComponent>; | |
beforeEach( | |
async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [HackerStatusComponent, TestHostComponent] | |
}).compileComponents(); | |
}) | |
); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(TestHostComponent); | |
testHost = fixture.componentInstance; | |
}); | |
it('should be created', () => { | |
expect(testHost).toBeTruthy(); | |
}); | |
it('should set pulse color to green when input is "safe"', () => { | |
testHost.appStatus = 'safe'; | |
fixture.detectChanges(); | |
const pulseEl: HTMLElement = fixture.debugElement.query(By.css('.pulse')) | |
.nativeElement; | |
expect(pulseEl.classList).toContain('green'); | |
}); | |
it('should set pulse color to green when input is "safe"', () => { | |
testHost.appStatus = 'safe'; | |
fixture.detectChanges(); | |
expect(fixture).toMatchSnapshot(); | |
}); | |
it('should set pulse color to yellow when input is "warning"', () => { | |
testHost.appStatus = 'warning'; | |
fixture.detectChanges(); | |
expect(fixture).toMatchSnapshot(); | |
}); | |
it('should set pulse color to red when input is "danger"', () => { | |
testHost.appStatus = 'danger'; | |
fixture.detectChanges(); | |
expect(fixture).toMatchSnapshot(); | |
}); | |
it('should set pulse color to green when input is undefined', () => { | |
fixture.detectChanges(); | |
expect(fixture).toMatchSnapshot(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment