Last active
June 22, 2016 08:23
-
-
Save ovrmrw/958992d15901141e6621f2552c268388 to your computer and use it in GitHub Desktop.
Helper to use power-assert in Jasmine testing space.
This file contains hidden or 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
export function asyncPower(asyncFunction: () => Promise<void>): Function { | |
return function (done) { | |
asyncFunction() | |
.then(() => done()) | |
.catch(e => done.fail(e.message)); | |
} | |
} |
This file contains hidden or 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
// testing for Angular2 component. | |
import assert from 'power-assert'; | |
import { asyncPower } from './async-power'; | |
describe('test', () => { | |
let builder: TestComponentBuilder; | |
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | |
builder = tcb; | |
})); | |
it('can create', asyncPower(async () => { | |
const fixture = await builder.createAsync(Page1Component); | |
assert(!!fixture); | |
})); | |
it('should have text: "page1 content."', asyncPower(async () => { | |
const fixture = await builder.createAsync(Page1Component); | |
const el = fixture.nativeElement as HTMLElement; | |
const CONTENT = 'h4'; | |
assert(el.querySelector(CONTENT).textContent === ''); | |
fixture.detectChanges(); | |
assert(el.querySelector(CONTENT).textContent === 'page1 content.'); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment