-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some simple tests to demonstrate testing directives and components #128
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we can move this
spec.bundle.js
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, see #129