Skip to content

Instantly share code, notes, and snippets.

@matthewdenobrega
Created January 4, 2016 11:15
Show Gist options
  • Save matthewdenobrega/3042444445dd66fa9679 to your computer and use it in GitHub Desktop.
Save matthewdenobrega/3042444445dd66fa9679 to your computer and use it in GitHub Desktop.
Catch handler to force unit tests to fail on exception
import {ComponentFixture, describe, expect, inject, it, TestComponentBuilder} from 'angular2/testing'
import {Component, View} from 'angular2/src/core/metadata'
@Component({ selector: 'basic-component' })
@View({ template: '<div></div>' })
class BasicComponent { }
// Set up the browser adapter
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter'
BrowserDomAdapter.makeCurrent()
describe('BasicComponent', () => {
it('should create a new component', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(BasicComponent).then((fixture: ComponentFixture) => {
expect(fixture.debugElement).not.toBe(null)
throw ('exception')
expect(false).toBe(true)
}).catch(() => {
expect(false).toBe(true)
})
}))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment