Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Last active June 22, 2016 08:23
Show Gist options
  • Save ovrmrw/958992d15901141e6621f2552c268388 to your computer and use it in GitHub Desktop.
Save ovrmrw/958992d15901141e6621f2552c268388 to your computer and use it in GitHub Desktop.
Helper to use power-assert in Jasmine testing space.
export function asyncPower(asyncFunction: () => Promise<void>): Function {
return function (done) {
asyncFunction()
.then(() => done())
.catch(e => done.fail(e.message));
}
}
// 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