Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('Compiler', ()=>{
var selector:Selector,
container,
binders,
attrDirectiveAnnotations;
it('should not reparent nodes', inject(Compiler, (compiler)=>{
createSelector();
container = $('<div>a</div>')[0];
var node = container.childNodes[0];
compiler._compile(container.childNodes, selector);
expect(node.parentNode).toBe(container);
}));
describe('mark nodes with directives and collect binders', ()=> {
it('should work for one element', function() {
createSelector([ new DecoratorDirective({selector: '[name]'}) ]);
// all possible combinations of elements with decorators and elements
// without decorators
compileAndVerifyBinders('<div></div>', '()');
compileAndVerifyBinders('<div name="1"></div>', '(),1()');
});
}
}
function serialize(linkedList) {
var res = [];
var item = linkedList.head;
while (item) {
res.push(item.data);
item = item.next;
}
return res.join('');
}
var a, b, c, d, list;
beforeEach(inject((injector) => {
a = new TestItem('a');
b = new TestItem('b');
c = new TestItem('c');
d = new TestItem('d');
list = new LinkedList();
}));
describe('append', () => {
it('should append in empty list', () => {
list.append(a);
expect(serialize(list)).toEqual('a');
expect(list.head).toBe(a);
expect(list.tail).toBe(a);
it('should resolve on window.load and remove the event listeners', (done)=>{
inject(DocumentReady, (dr)=>{
global.addEventListener.calls.mostRecent().args[1]();
dr.then(function(doc) {
expect(global.document.removeEventListener).toHaveBeenCalled();
expect(global.removeEventListener).toHaveBeenCalled();
expect(doc).toBe(global.document);
done();
});
});
});
it('should work in integration', (done)=>{
inject(ModuleLoader, (loadModules)=>{
loadModules(['test/loader/atemplate.html']).then((modules)=>{
return modules[0].promise;
}).then(function(data) {
expect(data.template.container.innerHTML.trim())
.toBe('\n\n<div>someTemplate</div>');
expect(data.modules['test/loader/amodule'].anExport).toBe(true);
done();
});
});
});
function compile(html) {
inject(Compiler, (compiler)=>{
container = $('<div></div>');
container.html(html);
var nodes = container.contents();
binders = compiler._compile(nodes, selector).elementBinders;
});
}
function compile(html, ctx={}) {
context = ctx;
inject(Compiler, Injector, (compiler, rootInjector) => {
container = $('<div>'+html+'</div>')[0];
var viewFactory = compiler.compileChildNodes(container, []);
rootView = viewFactory.createRootView(rootInjector, context, true);
});
}
function compile(html) {
inject(Compiler, ViewFactory, (compiler, viewFactory) => {
container = $('<div>'+html+'</div>')[0];
var compiledTemplate = compiler.compileChildNodes(container, [NgIf]);
view = viewFactory.createRootView({template: compiledTemplate});
anchor = container.lastChild;
});
}
function precompileAndEval(templateData, modules, done) {
var es6Source;
inject(Precompile, (precompile) =>{
es6Source = precompile(templateData, modules);
});
evalES6Module(es6Source, function(requireMod) {
requireMod.promise.then(function(data) {
done(data);
});
});
}
var define = require = function(deps, callback) {
inject(ModuleLoader, (moduleLoader)=>{
moduleLoader(deps).then(function(depModules) {
var module = callback(...depModules);
done(module);
});
});
}
eval(sourceES5);