How to use the di/testing.inject function in di

To help you get started, we’ve selected a few di examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / templating / test / compiler.spec.js View on Github external
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', ()=&gt; {
    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()');
    });
github angular / templating / test / util / linked_list.spec.js View on Github external
}
  }

  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);
github angular / templating / test / lib / util / document_ready.spec.js View on Github external
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();
        });
      });
    });
github angular / templating / test / loader / requirejs_html.spec.js View on Github external
it('should work in integration', (done)=&gt;{
    inject(ModuleLoader, (loadModules)=&gt;{
      loadModules(['test/loader/atemplate.html']).then((modules)=&gt;{
        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();
      });
    });
  });
github angular / templating / test / compiler.spec.js View on Github external
function compile(html) {
    inject(Compiler, (compiler)=&gt;{
      container = $('<div></div>');
      container.html(html);
      var nodes = container.contents();
      binders = compiler._compile(nodes, selector).elementBinders;
    });
  }
github angular / templating / test / integration / expressions.spec.js View on Github external
function compile(html, ctx={}) {
    context = ctx;
    inject(Compiler, Injector, (compiler, rootInjector) =&gt; {
      container = $('<div>'+html+'</div>')[0];
      var viewFactory = compiler.compileChildNodes(container, []);

      rootView = viewFactory.createRootView(rootInjector, context, true);
    });
  }
github angular / templating / test / integration / ng_if.spec.js View on Github external
function compile(html) {
    inject(Compiler, ViewFactory, (compiler, viewFactory) =&gt; {
      container = $('<div>'+html+'</div>')[0];
      var compiledTemplate = compiler.compileChildNodes(container, [NgIf]);

      view = viewFactory.createRootView({template: compiledTemplate});
      anchor = container.lastChild;
    });
  }
github angular / templating / test / loader / precompiler.spec.js View on Github external
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);
      });
    });
  }
github angular / templating / test / loader / precompiler.spec.js View on Github external
var define = require = function(deps, callback) {
      inject(ModuleLoader, (moduleLoader)=>{
        moduleLoader(deps).then(function(depModules) {
          var module = callback(...depModules);
          done(module);
        });
      });
    }
    eval(sourceES5);