-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from dotcs/implement-some-tests
Add some simple tests to demonstrate testing directives and components
- Loading branch information
Showing
4 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,64 @@ | ||
/// <reference path="../../src/typings/_custom.d.ts" /> | ||
|
||
// Select BrowserDomAdapter. | ||
// see https://github.com/AngularClass/angular2-webpack-starter/issues/124 | ||
var domAdapter = require('angular2/src/core/dom/browser_adapter').BrowserDomAdapter; | ||
domAdapter.makeCurrent(); | ||
|
||
// Import necessary wrappers for Jasmine | ||
import { | ||
beforeEachProviders, | ||
describe, | ||
expect, | ||
iit, | ||
inject, | ||
it, | ||
injectAsync, | ||
fakeAsync, | ||
TestComponentBuilder, | ||
tick | ||
} from 'angular2/testing'; | ||
import { Component, provide} from 'angular2/angular2'; | ||
import {MockBackend, BaseRequestOptions, Http} from 'angular2/http'; | ||
|
||
// Load the implementations that should be tested | ||
import { App, XLarge } from '../../src/app/app'; | ||
|
||
// Create a test component to test directives | ||
@Component({ | ||
template: '', | ||
directives: [XLarge] | ||
}) | ||
class TestComponent { | ||
} | ||
|
||
describe('x-large directive', () => { | ||
it('should sent font-size to x-large', injectAsync([TestComponentBuilder], (tcb) => { | ||
return tcb.overrideTemplate(TestComponent, '<div x-large>Content</div>') | ||
.createAsync(TestComponent).then((fixture: any) => { | ||
fixture.detectChanges(); | ||
let compiled = fixture.debugElement.nativeElement.children[0]; | ||
expect(compiled.style.fontSize).toBe('x-large'); | ||
}); | ||
})); | ||
|
||
}); | ||
|
||
describe('App', () => { | ||
// provide our implementations or mocks to the dependency injector | ||
beforeEachProviders(() => [ | ||
App, | ||
BaseRequestOptions, | ||
MockBackend, | ||
provide(Http, {useFactory: | ||
function(backend, defaultOptions) { | ||
return new Http(backend, defaultOptions); | ||
}, | ||
deps: [MockBackend, BaseRequestOptions]}) | ||
]); | ||
|
||
it('should also be able to test', () => { | ||
expect(true).toBe(true); | ||
}); | ||
it('should have a title', inject([App], (app) => { | ||
expect(app.title).toEqual('Angular 2'); | ||
})); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { | ||
it, | ||
describe, | ||
expect, | ||
inject | ||
} from 'angular2/testing'; | ||
import { | ||
APP_ID | ||
} from 'angular2/angular2'; | ||
|
||
|
||
describe('default test injector', () => { | ||
it('should provide default id', inject([APP_ID], (id) => { | ||
expect(id).toBe('a'); | ||
})); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('sanity checks', () => { | ||
it('should also be able to test', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |