<!DOCTYPE html>
<html>
<head>
<base href="." />
<title>angular2 playground</title>
<!-- Angular 2 Dependencies -->
<script src="https://unpkg.com/zone.js/dist/zone.js"></script>
<script src="https://unpkg.com/zone.js/dist/long-stack-trace-zone.js"></script>
<script src="https://unpkg.com/zone.js/dist/proxy.js"></script>
<script src="https://unpkg.com/zone.js/dist/sync-test.js"></script>
<script src="https://unpkg.com/zone.js/dist/async-test.js"></script>
<script src="https://unpkg.com/zone.js/dist/fake-async-test.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
<script src="config.js"></script>
<!-- Jasmine -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine-html.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/boot.js"></script>
<script src="https://unpkg.com/zone.js/dist/jasmine-patch.js"></script>
<script>
// Hack to start the tests after SystemJS has loaded its modules
var jasmineOnLoad = window.onload;
window.onload = function() {};
</script>
<!-- Angular 1 -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular-mocks.js"></script>
<script src="src/angular1.module.js"></script>
<script src="src/a1-test-component.js"></script>
<!-- Import and run tests -->
<script>
Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing'),
System.import('src/beforeEach'),
System.import('src/a1-test-component.spec')
])
.then(function(modules) {
var coreTesting = modules[ 0 ];
var browserTesting = modules[ 1 ];
coreTesting.TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());
})
.then(jasmineOnLoad) // start the tests
.catch(console.error.bind(console));
</script>
</head>
<body>
</body>
</html>
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {
'app': './src',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'rxjs': 'npm:rxjs',
'typescript': 'npm:typescript@2.0.2/lib/typescript.js'
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
}
}
});
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule, downgradeComponent, downgradeInjectable } from '@angular/upgrade/static';
import { AppComponent } from './app.component';
import { Angular2Service } from './angular2.service';
// Downgrade Angular 2 Service to Angular 1
angular.module( 'testApp' )
.factory( 'Angular2Service', downgradeInjectable( Angular2Service ) );
@NgModule({
imports: [ BrowserModule, UpgradeModule ],
providers : [ Angular2Service ]
})
export class AppModule {
ngDoBootstrap() {}
}
angular.module( 'testApp', [] );
//
// *** Comment out the below block to see the test pass
//
angular.module( 'testApp' )
.run( [ 'Angular2Service', Angular2Service => {
Angular2Service.showTestMessage();
} ] );
import { Injectable } from '@angular/core';
/**
* Just an example Angular 2 service which is downgraded
* to be run from Angular 1
*/
@Injectable()
export class Angular2Service {
showTestMessage() {
var msg = "Test Message from Angular 2 Service!";
document.body.appendChild( document.createTextNode( msg ) );
}
}
/**
* This is an example component test, such as one that
* is within our app.
*
* If 'Angular2Service' is not injected into the run()
* method of angular1.module.ts, this component test
* passes.
*/
describe( 'testComponent', () => {
var $compile,
$scope;
beforeEach( module( 'testApp' ) );
beforeEach( inject( $injector => {
$compile = $injector.get( '$compile' );
$scope = $injector.get( '$rootScope' ).$new();
} ) );
it( 'should show the text "Test Component" in the DOM', () => {
var element = $compile( '<test-component></test-component>' )( $scope );
$scope.$apply();
expect( element[ 0 ].innerHTML ).toBe( 'Test Component' );
} );
} );
/**
* This is an example component, such as one that is
* tested within our app.
*
* If 'Angular2Service' is not injected into the run()
* method of angular1.module.ts, this component's test
* passes.
*/
angular.module( 'testApp' ).component( 'testComponent', {
template: 'Test Component'
} );
import { async, TestBed } from '@angular/core/testing';
import { AppModule } from './app.module';
beforeEach( async( () => {
TestBed.configureTestingModule( {
imports : [ AppModule ]
} )
.compileComponents();
} ) );