2015-10-01 13:07:49 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
xdescribe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
inject,
|
|
|
|
beforeEachBindings
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-10-01 13:07:49 -04:00
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
import {Component, View, provide} from 'angular2/core';
|
2015-10-01 13:07:49 -04:00
|
|
|
import {PromiseWrapper} from 'angular2/src/core/facade/async';
|
2015-11-05 17:07:57 -05:00
|
|
|
import {SpyProtoViewFactory} from '../core/spies';
|
2015-10-01 13:07:49 -04:00
|
|
|
import {
|
|
|
|
CompiledHostTemplate,
|
|
|
|
CompiledTemplate,
|
|
|
|
BeginComponentCmd
|
2015-10-02 10:37:23 -04:00
|
|
|
} from 'angular2/src/core/linker/template_commands';
|
2015-11-05 17:07:57 -05:00
|
|
|
import {RuntimeCompiler} from 'angular2/src/compiler/runtime_compiler';
|
2015-10-02 10:37:23 -04:00
|
|
|
import {ProtoViewFactory} from 'angular2/src/core/linker/proto_view_factory';
|
|
|
|
import {AppProtoView} from 'angular2/src/core/linker/view';
|
2015-10-01 13:07:49 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('RuntimeCompiler', () => {
|
|
|
|
var compiler: RuntimeCompiler;
|
|
|
|
|
|
|
|
beforeEach(inject([RuntimeCompiler], (_compiler) => { compiler = _compiler; }));
|
|
|
|
|
|
|
|
describe('compileInHost', () => {
|
|
|
|
var protoViewFactorySpy;
|
|
|
|
var someProtoView;
|
|
|
|
|
|
|
|
beforeEachBindings(() => {
|
|
|
|
protoViewFactorySpy = new SpyProtoViewFactory();
|
|
|
|
someProtoView = new AppProtoView(null, null, null, null, null, null);
|
|
|
|
protoViewFactorySpy.spy('createHost').andReturn(someProtoView);
|
2015-10-12 14:30:34 -04:00
|
|
|
return [provide(ProtoViewFactory, {useValue: protoViewFactorySpy})];
|
2015-10-01 13:07:49 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should compile the template via TemplateCompiler',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
var cht: CompiledHostTemplate;
|
|
|
|
protoViewFactorySpy.spy('createHost')
|
|
|
|
.andCallFake((_cht) => {
|
|
|
|
cht = _cht;
|
|
|
|
return someProtoView;
|
|
|
|
});
|
|
|
|
compiler.compileInHost(SomeComponent)
|
|
|
|
.then((_) => {
|
|
|
|
var beginComponentCmd =
|
|
|
|
<BeginComponentCmd>cht.getTemplate().getData('app1').commands[0];
|
|
|
|
expect(beginComponentCmd.name).toEqual('some-comp');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should cache the result', inject([AsyncTestCompleter], (async) => {
|
|
|
|
PromiseWrapper
|
|
|
|
.all([compiler.compileInHost(SomeComponent), compiler.compileInHost(SomeComponent)])
|
|
|
|
.then((protoViewRefs) => {
|
|
|
|
expect(protoViewRefs[0]).toBe(protoViewRefs[1]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should clear the cache',
|
|
|
|
inject([AsyncTestCompleter], (async) => {compiler.compileInHost(SomeComponent)
|
|
|
|
.then((protoViewRef1) => {
|
|
|
|
compiler.clearCache();
|
|
|
|
compiler.compileInHost(SomeComponent)
|
|
|
|
.then((protoViewRef2) => {
|
|
|
|
expect(protoViewRef1)
|
|
|
|
.not.toBe(protoViewRef2);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
})}));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'some-comp'})
|
|
|
|
@View({template: ''})
|
|
|
|
class SomeComponent {
|
2015-10-02 10:37:23 -04:00
|
|
|
}
|