• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript test_lib.it函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中angular2/test_lib.it函数的典型用法代码示例。如果您正苦于以下问题:TypeScript it函数的具体用法?TypeScript it怎么用?TypeScript it使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了it函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

      describe(`${name} shadow dom strategy`, () => {

        it('should support simple components',
           inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
             tb.compileAll([
                 mainDir,
                 new ViewDefinition({
                   componentId: 'main',
                   template: '<simple>' +
                                 '<div>A</div>' +
                                 '</simple>',
                   directives: [simple]
                 }),
                 simpleTemplate
               ])
                 .then((protoViews) => {
                   tb.createRootViews(protoViews);

                   expect(tb.rootEl).toHaveText('SIMPLE(A)');

                   async.done();
                 });
           }));

        it('should not show the light dom even if there is not content tag',
           inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
             tb.compileAll([
                 mainDir,
                 new ViewDefinition({
                   componentId: 'main',
                   template: '<empty>' +
                                 '<div>A</div>' +
                                 '</empty>',
                   directives: [empty]
                 }),
                 emptyTemplate
               ])
                 .then((protoViews) => {
                   tb.createRootViews(protoViews);

                   expect(tb.rootEl).toHaveText('');

                   async.done();
                 });
           }));

        it('should support dynamic components',
           inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
             tb.compileAll([
                 mainDir,
                 new ViewDefinition({
                   componentId: 'main',
                   template: '<dynamic>' +
                                 '<div>A</div>' +
                                 '</dynamic>',
                   directives: [dynamicComponent]
                 }),
                 simpleTemplate
               ])
                 .then((protoViews) => {
                   var views = tb.createRootViews(ListWrapper.slice(protoViews, 0, 2));
                   tb.createComponentView(views[1].viewRef, 0, protoViews[2]);

                   expect(tb.rootEl).toHaveText('SIMPLE(A)');

                   async.done();
                 });
           }));

        it('should support multiple content tags',
           inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
             tb.compileAll([
                 mainDir,
                 new ViewDefinition({
                   componentId: 'main',
                   template: '<multiple-content-tags>' +
                                 '<div>B</div>' +
                                 '<div>C</div>' +
                                 '<div class="left">A</div>' +
                                 '</multiple-content-tags>',
                   directives: [multipleContentTagsComponent]
                 }),
                 multipleContentTagsTemplate
               ])
                 .then((protoViews) => {
                   tb.createRootViews(protoViews);

                   expect(tb.rootEl).toHaveText('(A, BC)');

                   async.done();
                 });
           }));

        it('should redistribute only direct children',
           inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
             tb.compileAll([
                 mainDir,
                 new ViewDefinition({
                   componentId: 'main',
                   template: '<multiple-content-tags>' +
//.........这里部分代码省略.........
开发者ID:B-Thapa,项目名称:angular,代码行数:101,代码来源:shadow_dom_emulation_integration_spec.ts


示例2: describe

 describe('compiler', function() {
   var mockStepFactory;
   function createCompiler(processClosure, urlData = null) {
     if (isBlank(urlData)) {
       urlData = MapWrapper.create();
     }
     var tplLoader = new FakeTemplateLoader(urlData);
     mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
     return new Compiler(mockStepFactory, tplLoader);
   }
   it('should run the steps and build the ProtoView of the root element', inject([AsyncTestCompleter], (async) => {
     var compiler = createCompiler((parent, current, control) => {
       current.inheritedProtoView.bindVariable('b', 'a');
     });
     compiler.compile(new Template({
       componentId: 'someComponent',
       inline: '<div></div>'
     })).then((protoView) => {
       expect(protoView.variableBindings).toEqual(MapWrapper.createFromStringMap({'a': 'b'}));
       async.done();
     });
   }));
   it('should use the inline template and compile in sync', inject([AsyncTestCompleter], (async) => {
     var compiler = createCompiler(EMPTY_STEP);
     compiler.compile(new Template({
       componentId: 'someId',
       inline: 'inline component'
     })).then((protoView) => {
       expect(DOM.getInnerHTML(protoView.render.delegate.element)).toEqual('inline component');
       async.done();
     });
   }));
   it('should load url templates', inject([AsyncTestCompleter], (async) => {
     var urlData = MapWrapper.createFromStringMap({'someUrl': 'url component'});
     var compiler = createCompiler(EMPTY_STEP, urlData);
     compiler.compile(new Template({
       componentId: 'someId',
       absUrl: 'someUrl'
     })).then((protoView) => {
       expect(DOM.getInnerHTML(protoView.render.delegate.element)).toEqual('url component');
       async.done();
     });
   }));
   it('should report loading errors', inject([AsyncTestCompleter], (async) => {
     var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
     PromiseWrapper.catchError(compiler.compile(new Template({
       componentId: 'someId',
       absUrl: 'someUrl'
     })), (e) => {
       expect(e.message).toContain(`Failed to load the template "someId"`);
       async.done();
     });
   }));
   it('should wait for async subtasks to be resolved', inject([AsyncTestCompleter], (async) => {
     var subTasksCompleted = false;
     var completer = PromiseWrapper.completer();
     var compiler = createCompiler((parent, current, control) => {
       ListWrapper.push(mockStepFactory.subTaskPromises, completer.promise.then((_) => {
         subTasksCompleted = true;
       }));
     });
     var pvPromise = compiler.compile(new Template({
       componentId: 'someId',
       inline: 'some component'
     }));
     expect(pvPromise).toBePromise();
     expect(subTasksCompleted).toEqual(false);
     completer.resolve(null);
     pvPromise.then((protoView) => {
       expect(subTasksCompleted).toEqual(true);
       async.done();
     });
   }));
 });
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:74,代码来源:compiler_common_tests.ts


示例3: describe

  describe('runner', () => {
    var injector: Injector;
    var runner;

    function createRunner(defaultBindings = null) {
      if (isBlank(defaultBindings)) {
        defaultBindings = [];
      }
      runner = new Runner([
        defaultBindings,
        bind(Sampler).toFactory(
            (_injector) => {
              injector = _injector;
              return new MockSampler();
            },
            [Injector]),
        bind(Metric).toFactory(() => new MockMetric(), []),
        bind(Validator).toFactory(() => new MockValidator(), []),
        bind(WebDriverAdapter).toFactory(() => new MockWebDriverAdapter(), [])
      ]);
      return runner;
    }

    it('should set SampleDescription.id', inject([AsyncTestCompleter], (async) => {
         createRunner()
             .sample({id: 'someId'})
             .then((_) => injector.get(SampleDescription))
             .then((desc) => {
               expect(desc.id).toBe('someId');
               async.done();
             });
       }));

    it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => {
         createRunner([bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})])
             .sample({id: 'someId', bindings: [bind(Options.SAMPLE_DESCRIPTION).toValue({'b': 2})]})
             .then((_) => injector.get(SampleDescription))
             .then((desc) => {
               expect(desc.description)
                   .toEqual(
                       {'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
               async.done();
             });
       }));

    it('should fill SampleDescription.metrics from the Metric',
       inject([AsyncTestCompleter], (async) => {
         createRunner()
             .sample({id: 'someId'})
             .then((_) => injector.get(SampleDescription))
             .then((desc) => {

               expect(desc.metrics).toEqual({'m1': 'some metric'});
               async.done();
             });
       }));

    it('should bind Options.EXECUTE', inject([AsyncTestCompleter], (async) => {
         var execute = () => {};
         createRunner()
             .sample({id: 'someId', execute: execute})
             .then((_) => {
               expect(injector.get(Options.EXECUTE)).toEqual(execute);
               async.done();
             });
       }));

    it('should bind Options.PREPARE', inject([AsyncTestCompleter], (async) => {
         var prepare = () => {};
         createRunner()
             .sample({id: 'someId', prepare: prepare})
             .then((_) => {
               expect(injector.get(Options.PREPARE)).toEqual(prepare);
               async.done();
             });
       }));

    it('should bind Options.MICRO_METRICS', inject([AsyncTestCompleter], (async) => {
         createRunner()
             .sample({id: 'someId', microMetrics: {'a': 'b'}})
             .then((_) => {
               expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
               async.done();
             });
       }));

    it('should overwrite bindings per sample call', inject([AsyncTestCompleter], (async) => {
         createRunner([
           bind(Options.DEFAULT_DESCRIPTION)
               .toValue({'a': 1}),
         ])
             .sample({
               id: 'someId',
               bindings: [
                 bind(Options.DEFAULT_DESCRIPTION)
                     .toValue({'a': 2}),
               ]
             })
             .then((_) => injector.get(SampleDescription))
             .then((desc) => {
//.........这里部分代码省略.........
开发者ID:goderbauer,项目名称:angular,代码行数:101,代码来源:runner_spec.ts


示例4: describe

  describe('StyleUrlResolver', () => {
    let styleUrlResolver;

    beforeEach(() => { styleUrlResolver = new StyleUrlResolver(new UrlResolver()); });

    it('should resolve "url()" urls', () => {
      var css = `
      .foo {
        background-image: url("double.jpg");
        background-image: url('simple.jpg');
        background-image: url(noquote.jpg);
      }`;
      var expectedCss = `
      .foo {
        background-image: url('http://ng.io/double.jpg');
        background-image: url('http://ng.io/simple.jpg');
        background-image: url('http://ng.io/noquote.jpg');
      }`;

      var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
      expect(resolvedCss).toEqual(expectedCss);
    });

    it('should resolve "@import" urls', () => {
      var css = `
      @import '1.css';
      @import "2.css";
      `;
      var expectedCss = `
      @import 'http://ng.io/1.css';
      @import 'http://ng.io/2.css';
      `;

      var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
      expect(resolvedCss).toEqual(expectedCss);
    });

    it('should resolve "@import url()" urls', () => {
      var css = `
      @import url('3.css');
      @import url("4.css");
      @import url(5.css);
      `;
      var expectedCss = `
      @import url('http://ng.io/3.css');
      @import url('http://ng.io/4.css');
      @import url('http://ng.io/5.css');
      `;

      var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
      expect(resolvedCss).toEqual(expectedCss);
    });

    it('should support media query in "@import"', () => {
      var css = `
      @import 'print.css' print;
      @import url(print.css) print;
      `;
      var expectedCss = `
      @import 'http://ng.io/print.css' print;
      @import url('http://ng.io/print.css') print;
      `;

      var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
      expect(resolvedCss).toEqual(expectedCss);
    });
  });
开发者ID:cedriclam,项目名称:angular,代码行数:67,代码来源:style_url_resolver_spec.ts


示例5: describe

  describe('CssSelector.parse', () => {
    it('should detect element names', () => {
      var cssSelector = CssSelector.parse('sometag')[0];
      expect(cssSelector.element).toEqual('sometag');
      expect(cssSelector.toString()).toEqual('sometag');
    });

    it('should detect class names', () => {
      var cssSelector = CssSelector.parse('.someClass')[0];
      expect(cssSelector.classNames).toEqual(['someclass']);

      expect(cssSelector.toString()).toEqual('.someclass');
    });

    it('should detect attr names', () => {
      var cssSelector = CssSelector.parse('[attrname]')[0];
      expect(cssSelector.attrs).toEqual(['attrname', '']);

      expect(cssSelector.toString()).toEqual('[attrname]');
    });

    it('should detect attr values', () => {
      var cssSelector = CssSelector.parse('[attrname=attrvalue]')[0];
      expect(cssSelector.attrs).toEqual(['attrname', 'attrvalue']);
      expect(cssSelector.toString()).toEqual('[attrname=attrvalue]');
    });

    it('should detect multiple parts', () => {
      var cssSelector = CssSelector.parse('sometag[attrname=attrvalue].someclass')[0];
      expect(cssSelector.element).toEqual('sometag');
      expect(cssSelector.attrs).toEqual(['attrname', 'attrvalue']);
      expect(cssSelector.classNames).toEqual(['someclass']);

      expect(cssSelector.toString()).toEqual('sometag.someclass[attrname=attrvalue]');
    });

    it('should detect multiple attributes', () => {
      var cssSelector = CssSelector.parse('input[type=text][control]')[0];
      expect(cssSelector.element).toEqual('input');
      expect(cssSelector.attrs).toEqual(['type', 'text', 'control', '']);

      expect(cssSelector.toString()).toEqual('input[type=text][control]');
    });

    it('should detect :not', () => {
      var cssSelector = CssSelector.parse('sometag:not([attrname=attrvalue].someclass)')[0];
      expect(cssSelector.element).toEqual('sometag');
      expect(cssSelector.attrs.length).toEqual(0);
      expect(cssSelector.classNames.length).toEqual(0);

      var notSelector = cssSelector.notSelectors[0];
      expect(notSelector.element).toEqual(null);
      expect(notSelector.attrs).toEqual(['attrname', 'attrvalue']);
      expect(notSelector.classNames).toEqual(['someclass']);

      expect(cssSelector.toString()).toEqual('sometag:not(.someclass[attrname=attrvalue])');
    });

    it('should detect :not without truthy', () => {
      var cssSelector = CssSelector.parse(':not([attrname=attrvalue].someclass)')[0];
      expect(cssSelector.element).toEqual("*");

      var notSelector = cssSelector.notSelectors[0];
      expect(notSelector.attrs).toEqual(['attrname', 'attrvalue']);
      expect(notSelector.classNames).toEqual(['someclass']);

      expect(cssSelector.toString()).toEqual('*:not(.someclass[attrname=attrvalue])');
    });

    it('should throw when nested :not', () => {
      expect(() => { CssSelector.parse('sometag:not(:not([attrname=attrvalue].someclass))')[0]; })
          .toThrowError('Nesting :not is not allowed in a selector');
    });

    it('should throw when multiple selectors in :not', () => {
      expect(() => { CssSelector.parse('sometag:not(a,b)'); })
          .toThrowError('Multiple selectors in :not are not supported');
    });

    it('should detect lists of selectors', () => {
      var cssSelectors = CssSelector.parse('.someclass,[attrname=attrvalue], sometag');
      expect(cssSelectors.length).toEqual(3);

      expect(cssSelectors[0].classNames).toEqual(['someclass']);
      expect(cssSelectors[1].attrs).toEqual(['attrname', 'attrvalue']);
      expect(cssSelectors[2].element).toEqual('sometag');
    });

    it('should detect lists of selectors with :not', () => {
      var cssSelectors =
          CssSelector.parse('input[type=text], :not(textarea), textbox:not(.special)');
      expect(cssSelectors.length).toEqual(3);

      expect(cssSelectors[0].element).toEqual('input');
      expect(cssSelectors[0].attrs).toEqual(['type', 'text']);

      expect(cssSelectors[1].element).toEqual('*');
      expect(cssSelectors[1].notSelectors[0].element).toEqual('textarea');

      expect(cssSelectors[2].element).toEqual('textbox');
//.........这里部分代码省略.........
开发者ID:AsherBarak,项目名称:angular,代码行数:101,代码来源:selector_spec.ts


示例6: describe

  describe('exceptions', () => {
    it('should call the on error callback when it is defined',
       inject([AsyncTestCompleter], (async) => {
         macroTask(() => {
           _zone.overrideOnErrorHandler(logError);

           var exception = new BaseException('sync');

           _zone.run(() => { throw exception; });

           expect(_errors.length).toBe(1);
           expect(_errors[0]).toBe(exception);
           async.done();
         });
       }));

    it('should call onError for errors from microtasks', inject([AsyncTestCompleter], (async) => {
         _zone.overrideOnErrorHandler(logError);

         var exception = new BaseException('async');

         macroTask(() => { _zone.run(() => { microTask(() => { throw exception; }); }); });

         macroTask(() => {
           expect(_errors.length).toBe(1);
           expect(_errors[0]).toEqual(exception);
           async.done();
         }, 80);
       }));

    it('should call onError when onTurnDone throws and the zone is sync',
       inject([AsyncTestCompleter], (async) => {
         var exception = new BaseException('fromOnTurnDone');

         _zone.overrideOnErrorHandler(logError);
         _zone.overrideOnTurnDone(() => { throw exception; });

         macroTask(() => { _zone.run(() => {}); });

         macroTask(() => {
           expect(_errors.length).toBe(1);
           expect(_errors[0]).toEqual(exception);
           async.done();
         }, 80);
       }));

    it('should call onError when onTurnDone throws and the zone is async',
       inject([AsyncTestCompleter], (async) => {
         var asyncRan = false;

         var exception = new BaseException('fromOnTurnDone');

         _zone.overrideOnErrorHandler(logError);
         _zone.overrideOnTurnDone(() => { throw exception; });

         macroTask(() => { _zone.run(() => { microTask(() => { asyncRan = true; }); }); });

         macroTask(() => {
           expect(asyncRan).toBe(true);
           expect(_errors.length).toBe(1);
           expect(_errors[0]).toEqual(exception);
           async.done();
         }, 80);
       }));
  });
开发者ID:goderbauer,项目名称:angular,代码行数:65,代码来源:ng_zone_spec.ts


示例7: describe

 describe('injector', function() {
   it('should instantiate a class without dependencies', function() {
     var injector = new Injector([Engine]);
     var engine = injector.get(Engine);
     expect(engine).toBeAnInstanceOf(Engine);
   });
   it('should resolve dependencies based on type information', function() {
     var injector = new Injector([Engine, Car]);
     var car = injector.get(Car);
     expect(car).toBeAnInstanceOf(Car);
     expect(car.engine).toBeAnInstanceOf(Engine);
   });
   it('should resolve dependencies based on @Inject annotation', function() {
     var injector = new Injector([TurboEngine, Engine, CarWithInject]);
     var car = injector.get(CarWithInject);
     expect(car).toBeAnInstanceOf(CarWithInject);
     expect(car.engine).toBeAnInstanceOf(TurboEngine);
   });
   it('should throw when no type and not @Inject', function() {
     expect(() => new Injector([NoAnnotations])).toThrowError('Cannot resolve all parameters for NoAnnotations');
   });
   it('should cache instances', function() {
     var injector = new Injector([Engine]);
     var e1 = injector.get(Engine);
     var e2 = injector.get(Engine);
     expect(e1).toBe(e2);
   });
   it('should bind to a value', function() {
     var injector = new Injector([bind(Engine).toValue("fake engine")]);
     var engine = injector.get(Engine);
     expect(engine).toEqual("fake engine");
   });
   it('should bind to a factory', function() {
     function sportsCarFactory(e) {
       return new SportsCar(e);
     }
     Object.defineProperty(sportsCarFactory, "parameters", {get: function() {
         return [[Engine]];
       }});
     var injector = new Injector([Engine, bind(Car).toFactory(sportsCarFactory)]);
     var car = injector.get(Car);
     expect(car).toBeAnInstanceOf(SportsCar);
     expect(car.engine).toBeAnInstanceOf(Engine);
   });
   it('should bind to an alias', function() {
     var injector = new Injector([Engine, bind(SportsCar).toClass(SportsCar), bind(Car).toAlias(SportsCar)]);
     var car = injector.get(Car);
     var sportsCar = injector.get(SportsCar);
     expect(car).toBeAnInstanceOf(SportsCar);
     expect(car).toBe(sportsCar);
   });
   it('should throw when the aliased binding does not exist', function() {
     var injector = new Injector([bind('car').toAlias(SportsCar)]);
     expect(() => injector.get('car')).toThrowError('No provider for SportsCar! (car -> SportsCar)');
   });
   it('should support overriding factory dependencies', function() {
     var injector = new Injector([Engine, bind(Car).toFactory((e) => new SportsCar(e), [Engine])]);
     var car = injector.get(Car);
     expect(car).toBeAnInstanceOf(SportsCar);
     expect(car.engine).toBeAnInstanceOf(Engine);
   });
   it('should support optional dependencies', function() {
     var injector = new Injector([CarWithOptionalEngine]);
     var car = injector.get(CarWithOptionalEngine);
     expect(car.engine).toEqual(null);
   });
   it("should flatten passed-in bindings", function() {
     var injector = new Injector([[[Engine, Car]]]);
     var car = injector.get(Car);
     expect(car).toBeAnInstanceOf(Car);
   });
   it("should use the last binding " + "when there are mutliple bindings for same token", function() {
     var injector = new Injector([bind(Engine).toClass(Engine), bind(Engine).toClass(TurboEngine)]);
     expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
   });
   it('should use non-type tokens', function() {
     var injector = new Injector([bind('token').toValue('value')]);
     expect(injector.get('token')).toEqual('value');
   });
   it('should throw when given invalid bindings', function() {
     expect(() => new Injector(["blah"])).toThrowError('Invalid binding blah');
     expect(() => new Injector([bind("blah")])).toThrowError('Invalid binding blah');
   });
   it('should provide itself', function() {
     var parent = new Injector([]);
     var child = parent.createChild([]);
     expect(child.get(Injector)).toBe(child);
   });
   it('should throw when no provider defined', function() {
     var injector = new Injector([]);
     expect(() => injector.get('NonExisting')).toThrowError('No provider for NonExisting!');
   });
   it('should show the full path when no provider', function() {
     var injector = new Injector([CarWithDashboard, Engine, Dashboard]);
     expect(() => injector.get(CarWithDashboard)).toThrowError('No provider for DashboardSoftware! (CarWithDashboard -> Dashboard -> DashboardSoftware)');
   });
   it('should throw when trying to instantiate a cyclic dependency', function() {
     var injector = new Injector([Car, bind(Engine).toClass(CyclicEngine)]);
     expect(() => injector.get(Car)).toThrowError('Cannot instantiate cyclic dependency! (Car -> Engine -> Car)');
     expect(() => injector.asyncGet(Car)).toThrowError('Cannot instantiate cyclic dependency! (Car -> Engine -> Car)');
//.........这里部分代码省略.........
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:101,代码来源:injector_spec.ts


示例8: describe

      describe("optional components", () => {
        describe("contains", () => {
          var group;

          beforeEach(() => {
            group = new ControlGroup(
                {
                  "required": new Control("requiredValue"),
                  "optional": new Control("optionalValue")
                },
                {"optional": false});
          });

          // rename contains into has
          it("should return false when the component is not included",
             () => { expect(group.contains("optional")).toEqual(false); })

              it("should return false when there is no component with the given name",
                 () => { expect(group.contains("something else")).toEqual(false); });

          it("should return true when the component is included", () => {
            expect(group.contains("required")).toEqual(true);

            group.include("optional");

            expect(group.contains("optional")).toEqual(true);
          });
        });

        it("should not include an inactive component into the group value", () => {
          var group = new ControlGroup(
              {"required": new Control("requiredValue"), "optional": new Control("optionalValue")},
              {"optional": false});

          expect(group.value).toEqual({"required": "requiredValue"});

          group.include("optional");

          expect(group.value).toEqual({"required": "requiredValue", "optional": "optionalValue"});
        });

        it("should not run Validators on an inactive component", () => {
          var group = new ControlGroup(
              {
                "required": new Control("requiredValue", Validators.required),
                "optional": new Control("", Validators.required)
              },
              {"optional": false});

          expect(group.valid).toEqual(true);

          group.include("optional");

          expect(group.valid).toEqual(false);
        });

        describe("valueChanges", () => {
          var g, c1, c2;

          beforeEach(() => {
            c1 = new Control("old1");
            c2 = new Control("old2");
            g = new ControlGroup({"one": c1, "two": c2}, {"two": true});
          });

          it("should fire an event after the value has been updated",
             inject([AsyncTestCompleter], (async) => {
               ObservableWrapper.subscribe(g.valueChanges, (value) => {
                 expect(g.value).toEqual({'one': 'new1', 'two': 'old2'});
                 expect(value).toEqual({'one': 'new1', 'two': 'old2'});
                 async.done();
               });
               c1.updateValue("new1");
             }));

          it("should fire an event after the control's observable fired an event",
             inject([AsyncTestCompleter], (async) => {
               var controlCallbackIsCalled = false;

               ObservableWrapper.subscribe(c1.valueChanges,
                                           (value) => { controlCallbackIsCalled = true; });

               ObservableWrapper.subscribe(g.valueChanges, (value) => {
                 expect(controlCallbackIsCalled).toBe(true);
                 async.done();
               });

               c1.updateValue("new1");
             }));

          it("should fire an event when a control is excluded",
             inject([AsyncTestCompleter], (async) => {
               ObservableWrapper.subscribe(g.valueChanges, (value) => {
                 expect(value).toEqual({'one': 'old1'});
                 async.done();
               });

               g.exclude("two");
             }));

//.........这里部分代码省略.........
开发者ID:188799958,项目名称:angular,代码行数:101,代码来源:model_spec.ts


示例9: describe

  describe('URLSearchParams', () => {
    it('should conform to spec', () => {
      var paramsString = "q=URLUtils.searchParams&topic=api";
      var searchParams = new URLSearchParams(paramsString);

      // Tests borrowed from example at
      // https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
      // Compliant with spec described at https://url.spec.whatwg.org/#urlsearchparams
      expect(searchParams.has("topic")).toBe(true);
      expect(searchParams.has("foo")).toBe(false);
      expect(searchParams.get("topic")).toEqual("api");
      expect(searchParams.getAll("topic")).toEqual(["api"]);
      expect(searchParams.get("foo")).toBe(null);
      searchParams.append("topic", "webdev");
      expect(searchParams.getAll("topic")).toEqual(["api", "webdev"]);
      expect(searchParams.toString()).toEqual("q=URLUtils.searchParams&topic=api&topic=webdev");
      searchParams.delete("topic");
      expect(searchParams.toString()).toEqual("q=URLUtils.searchParams");

      // Test default constructor
      expect(new URLSearchParams().toString()).toBe("");
    });


    it('should support map-like merging operation via setAll()', () => {
      var mapA = new URLSearchParams('a=1&a=2&a=3&c=8');
      var mapB = new URLSearchParams('a=4&a=5&a=6&b=7');
      mapA.setAll(mapB);
      expect(mapA.has('a')).toBe(true);
      expect(mapA.has('b')).toBe(true);
      expect(mapA.has('c')).toBe(true);
      expect(mapA.getAll('a')).toEqual(['4']);
      expect(mapA.getAll('b')).toEqual(['7']);
      expect(mapA.getAll('c')).toEqual(['8']);
      expect(mapA.toString()).toEqual('a=4&c=8&b=7');
    });


    it('should support multimap-like merging operation via appendAll()', () => {
      var mapA = new URLSearchParams('a=1&a=2&a=3&c=8');
      var mapB = new URLSearchParams('a=4&a=5&a=6&b=7');
      mapA.appendAll(mapB);
      expect(mapA.has('a')).toBe(true);
      expect(mapA.has('b')).toBe(true);
      expect(mapA.has('c')).toBe(true);
      expect(mapA.getAll('a')).toEqual(['1', '2', '3', '4', '5', '6']);
      expect(mapA.getAll('b')).toEqual(['7']);
      expect(mapA.getAll('c')).toEqual(['8']);
      expect(mapA.toString()).toEqual('a=1&a=2&a=3&a=4&a=5&a=6&c=8&b=7');
    });


    it('should support multimap-like merging operation via replaceAll()', () => {
      var mapA = new URLSearchParams('a=1&a=2&a=3&c=8');
      var mapB = new URLSearchParams('a=4&a=5&a=6&b=7');
      mapA.replaceAll(mapB);
      expect(mapA.has('a')).toBe(true);
      expect(mapA.has('b')).toBe(true);
      expect(mapA.has('c')).toBe(true);
      expect(mapA.getAll('a')).toEqual(['4', '5', '6']);
      expect(mapA.getAll('b')).toEqual(['7']);
      expect(mapA.getAll('c')).toEqual(['8']);
      expect(mapA.toString()).toEqual('a=4&a=5&a=6&c=8&b=7');
    });
  });
开发者ID:goderbauer,项目名称:angular,代码行数:65,代码来源:url_search_params_spec.ts


示例10: describe

    describe('compile', () => {

      it('should run the steps and build the AppProtoView of the root element',
         inject([AsyncTestCompleter], (async) => {
           var compiler = createCompiler((parent, current, control) => {
             current.inheritedProtoView.bindVariable('b', 'a');
           });
           compiler.compile(
                       new ViewDefinition({componentId: 'someComponent', template: '<div></div>'}))
               .then((protoView) => {
                 expect(protoView.variableBindings)
                     .toEqual(MapWrapper.createFromStringMap({'a': 'b'}));
                 async.done();
               });
         }));

      it('should run the steps and build the proto view', inject([AsyncTestCompleter], (async) => {
           var compiler = createCompiler((parent, current, control) => {
             current.inheritedProtoView.bindVariable('b', 'a');
           });

           var dirMetadata = DirectiveMetadata.create(
               {id: 'id', selector: 'CUSTOM', type: DirectiveMetadata.COMPONENT_TYPE});
           compiler.compileHost(dirMetadata)
               .then((protoView) => {
                 expect(DOM.tagName(resolveInternalDomProtoView(protoView.render).element))
                     .toEqual('CUSTOM');
                 expect(mockStepFactory.viewDef.directives).toEqual([dirMetadata]);
                 expect(protoView.variableBindings)
                     .toEqual(MapWrapper.createFromStringMap({'a': 'b'}));
                 async.done();
               });
         }));

      it('should use the inline template and compile in sync',
         inject([AsyncTestCompleter], (async) => {
           var compiler = createCompiler(EMPTY_STEP);
           compiler.compile(
                       new ViewDefinition({componentId: 'someId', template: 'inline component'}))
               .then((protoView) => {
                 expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element))
                     .toEqual('inline component');
                 async.done();
               });
         }));

      it('should load url templates', inject([AsyncTestCompleter], (async) => {
           var urlData = MapWrapper.createFromStringMap({'someUrl': 'url component'});
           var compiler = createCompiler(EMPTY_STEP, urlData);
           compiler.compile(new ViewDefinition({componentId: 'someId', templateAbsUrl: 'someUrl'}))
               .then((protoView) => {
                 expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element))
                     .toEqual('url component');
                 async.done();
               });
         }));

      it('should report loading errors', inject([AsyncTestCompleter], (async) => {
           var compiler = createCompiler(EMPTY_STEP, new Map());
           PromiseWrapper.catchError(
               compiler.compile(
                   new ViewDefinition({componentId: 'someId', templateAbsUrl: 'someUrl'})),
               (e) => {
                 expect(e.message).toEqual(
                     'Failed to load the template for "someId" : Failed to fetch url "someUrl"');
                 async.done();
                 return null;
               });
         }));

      it('should return ProtoViews of type COMPONENT_VIEW_TYPE',
         inject([AsyncTestCompleter], (async) => {
           var compiler = createCompiler(EMPTY_STEP);
           compiler.compile(
                       new ViewDefinition({componentId: 'someId', template: 'inline component'}))
               .then((protoView) => {
                 expect(protoView.type).toEqual(ViewType.COMPONENT);
                 async.done();
               });
         }));

    });
开发者ID:cedriclam,项目名称:angular,代码行数:82,代码来源:compiler_common_tests.ts


示例11: describe

  describe('PropertyBindingParser', () => {
    function createPipeline(hasNestedProtoView = false) {
      return new CompilePipeline([
        new MockStep((parent, current, control) =>
                     {
                       if (hasNestedProtoView) {
                         current.bindElement().bindNestedProtoView(el('<template></template>'));
                       }
                     }),
        new PropertyBindingParser(new Parser(new Lexer()))
      ]);
    }

    function process(element, hasNestedProtoView = false): List<ElementBinderBuilder> {
      return ListWrapper.map(createPipeline(hasNestedProtoView).process(element),
                             (compileElement) => compileElement.inheritedElementBinder);
    }

    it('should detect [] syntax', () => {
      var results = process(el('<div [a]="b"></div>'));
      expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
    });

    it('should detect [] syntax only if an attribute name starts and ends with []', () => {
      expect(process(el('<div z[a]="b"></div>'))[0]).toBe(null);
      expect(process(el('<div [a]v="b"></div>'))[0]).toBe(null);
    });

    it('should detect bind- syntax', () => {
      var results = process(el('<div bind-a="b"></div>'));
      expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
    });

    it('should detect bind- syntax only if an attribute name starts with bind',
       () => { expect(process(el('<div _bind-a="b"></div>'))[0]).toEqual(null); });

    it('should detect interpolation syntax', () => {
      var results = process(el('<div a="{{b}}"></div>'));
      expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('{{b}}');
    });

    it('should store property setters as camel case', () => {
      var element = el('<div bind-some-prop="1">');
      var results = process(element);
      expect(MapWrapper.get(results[0].propertyBindings, 'someProp')).toBeTruthy();
    });

    it('should detect var- syntax', () => {
      var results = process(el('<template var-a="b"></template>'));
      expect(MapWrapper.get(results[0].variableBindings, 'b')).toEqual('a');
    });

    it('should store variable binding for a template element on the nestedProtoView', () => {
      var results = process(el('<template var-george="washington"></p>'), true);
      expect(results[0].variableBindings).toEqual(EMPTY_MAP);
      expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
          .toEqual('george');
    });

    it('should store variable binding for a non-template element using shorthand syntax on the nestedProtoView',
       () => {
         var results = process(el('<template #george="washington"></template>'), true);
         expect(results[0].variableBindings).toEqual(EMPTY_MAP);
         expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
             .toEqual('george');
       });

    it('should store variable binding for a non-template element', () => {
      var results = process(el('<p var-george="washington"></p>'));
      expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
    });

    it('should store variable binding for a non-template element using shorthand syntax', () => {
      var results = process(el('<p #george="washington"></p>'));
      expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
    });

    it('should store a variable binding with an implicit value', () => {
      var results = process(el('<p var-george></p>'));
      expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
    });

    it('should store a variable binding with an implicit value using shorthand syntax', () => {
      var results = process(el('<p #george></p>'));
      expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
    });

    it('should detect variable bindings only if an attribute name starts with #', () => {
      var results = process(el('<p b#george></p>'));
      expect(results[0]).toEqual(null);
    });

    it('should detect () syntax', () => {
      var results = process(el('<div (click)="b()"></div>'));
      var eventBinding = results[0].eventBindings[0];
      expect(eventBinding.source.source).toEqual('b()');
      expect(eventBinding.fullName).toEqual('click');
      // "(click[])" is not an expected syntax and is only used to validate the regexp
      results = process(el('<div (click[])="b()"></div>'));
      eventBinding = results[0].eventBindings[0];
//.........这里部分代码省略.........
开发者ID:188799958,项目名称:angular,代码行数:101,代码来源:property_binding_parser_spec.ts


示例12: describe

  describe('Location', () => {

    var locationStrategy, location;

    function makeLocation(baseHref: string = '/my/app', binding: any = CONST_EXPR([])): Location {
      locationStrategy = new MockLocationStrategy();
      locationStrategy.internalBaseHref = baseHref;
      let injector = Injector.resolveAndCreate(
          [Location, bind(LocationStrategy).toValue(locationStrategy), binding]);
      return location = injector.get(Location);
    }

    beforeEach(makeLocation);

    it('should normalize relative urls on navigate', () => {
      location.go('user/btford');
      expect(locationStrategy.path()).toEqual('/my/app/user/btford');
    });

    it('should not prepend urls with starting slash when an empty URL is provided',
       () => { expect(location.normalizeAbsolutely('')).toEqual(locationStrategy.getBaseHref()); });

    it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
      let location = makeLocation('/my/slashed/app/');
      expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page');
    });

    it('should not append urls with leading slash on navigate', () => {
      location.go('/my/app/user/btford');
      expect(locationStrategy.path()).toEqual('/my/app/user/btford');
    });

    it('should remove index.html from base href', () => {
      let location = makeLocation('/my/app/index.html');
      location.go('user/btford');
      expect(locationStrategy.path()).toEqual('/my/app/user/btford');
    });

    it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
         locationStrategy.simulatePopState('/my/app/user/btford');
         location.subscribe((ev) => {
           expect(ev['url']).toEqual('/user/btford');
           async.done();
         })
       }));

    it('should normalize location path', () => {
      locationStrategy.internalPath = '/my/app/user/btford';
      expect(location.path()).toEqual('/user/btford');
    });

    it('should use optional base href param', () => {
      let location = makeLocation('/', bind(APP_BASE_HREF).toValue('/my/custom/href'));
      location.go('user/btford');
      expect(locationStrategy.path()).toEqual('/my/custom/href/user/btford');
    });

    it('should throw when no base href is provided', () => {
      var locationStrategy = new MockLocationStrategy();
      locationStrategy.internalBaseHref = null;
      expect(() => new Location(locationStrategy))
          .toThrowError(
              `No base href set. Either provide a binding to "appBaseHrefToken" or add a base element.`);
    });

    it('should revert to the previous path when a back() operation is executed', () => {
      var locationStrategy = new MockLocationStrategy();
      var location = new Location(locationStrategy);

      function assertUrl(path) { expect(location.path()).toEqual(path); }

      location.go('/ready');
      assertUrl('/ready');

      location.go('/ready/set');
      assertUrl('/ready/set');

      location.go('/ready/set/go');
      assertUrl('/ready/set/go');

      location.back();
      assertUrl('/ready/set');

      location.back();
      assertUrl('/ready');
    });
  });
开发者ID:lavinjj,项目名称:angular,代码行数:87,代码来源:location_spec.ts


示例13: describe

  describe('RouteRegistry', () => {
    var registry, rootHostComponent = new Object();

    beforeEach(() => { registry = new RouteRegistry(); });

    it('should match the full URL', () => {
      registry.config(rootHostComponent, {'path': '/', 'component': DummyCompA});
      registry.config(rootHostComponent, {'path': '/test', 'component': DummyCompB});

      var instruction = registry.recognize('/test', rootHostComponent);

      expect(instruction.getChild('default').component).toBe(DummyCompB);
    });

    it('should prefer static segments to dynamic', () => {
      registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompB});
      registry.config(rootHostComponent, {'path': '/home', 'component': DummyCompA});

      var instruction = registry.recognize('/home', rootHostComponent);

      expect(instruction.getChild('default').component).toBe(DummyCompA);
    });

    it('should prefer dynamic segments to star', () => {
      registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompA});
      registry.config(rootHostComponent, {'path': '/*site', 'component': DummyCompB});

      var instruction = registry.recognize('/home', rootHostComponent);

      expect(instruction.getChild('default').component).toBe(DummyCompA);
    });

    it('should prefer routes with more dynamic segments', () => {
      registry.config(rootHostComponent, {'path': '/:first/*rest', 'component': DummyCompA});
      registry.config(rootHostComponent, {'path': '/*all', 'component': DummyCompB});

      var instruction = registry.recognize('/some/path', rootHostComponent);

      expect(instruction.getChild('default').component).toBe(DummyCompA);
    });

    it('should prefer routes with more static segments', () => {
      registry.config(rootHostComponent, {'path': '/first/:second', 'component': DummyCompA});
      registry.config(rootHostComponent, {'path': '/:first/:second', 'component': DummyCompB});

      var instruction = registry.recognize('/first/second', rootHostComponent);

      expect(instruction.getChild('default').component).toBe(DummyCompA);
    });

    it('should prefer routes with static segments before dynamic segments', () => {
      registry.config(rootHostComponent, {'path': '/first/second/:third', 'component': DummyCompB});
      registry.config(rootHostComponent, {'path': '/first/:second/third', 'component': DummyCompA});

      var instruction = registry.recognize('/first/second/third', root 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript test_lib.normalizeCSS函数代码示例发布时间:2022-05-25
下一篇:
TypeScript test_lib.isInInnerZone函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap