示例#1
0
    describe("PercentPipe", () => {
      var pipe;

      beforeEach(() => { pipe = new PercentPipe(); });

      describe("transform", () => {
        it('should return correct value for numbers', () => {
          expect(pipe.transform(1.23, [])).toEqual('123%');
          expect(pipe.transform(1.2, ['.2'])).toEqual('120.00%');
        });

        it("should not support other objects",
           () => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
      });
    });
  describe("DirectiveResolver", () => {
    var reader;

    beforeEach(() => { reader = new DirectiveResolver(); });

    it('should read out the Directive annotation', () => {
      var directiveMetadata = reader.resolve(SomeDirective);
      expect(directiveMetadata).toEqual(new dirAnn.Directive({selector: 'someDirective'}));
    });

    it('should throw if not matching annotation is found', () => {
      expect(() => { reader.resolve(SomeDirectiveWithoutAnnotation); })
          .toThrowError('No Directive annotation found on SomeDirectiveWithoutAnnotation');
    });
  });
示例#3
0
  describe("key", function() {
    var registry;

    beforeEach(function() { registry = new KeyRegistry(); });

    it('should be equal to another key if type is the same',
       function() { expect(registry.get('car')).toBe(registry.get('car')); });

    it('should not be equal to another key if types are different',
       function() { expect(registry.get('car')).not.toBe(registry.get('porsche')); });

    it('should return the passed in key',
       function() { expect(registry.get(registry.get('car'))).toBe(registry.get('car')); });

  });
示例#4
0
    describe("CurrencyPipe", () => {
      var pipe;

      beforeEach(() => { pipe = new CurrencyPipe(); });

      describe("transform", () => {
        it('should return correct value for numbers', () => {
          expect(pipe.transform(123, [])).toEqual('USD123');
          expect(pipe.transform(12, ['EUR', false, '.2'])).toEqual('EUR12.00');
        });

        it("should not support other objects",
           () => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
      });
    });
示例#5
0
文件: logo.spec.ts 项目: Luphia/Laria
	describe('logo', () => {
		var injector: Injector;
		var backend: MockBackend;
		var response;
		
		beforeEachBindings(() => [
			BaseRequestOptions,
			MockBackend,
			bind(Http).toFactory((connectionBackend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
				return new Http(connectionBackend, defaultOptions);
			}, [
				MockBackend,
				BaseRequestOptions
			]),
			bind(IconStore).toClass(IconStore, [
				Http
			])
		]);

		beforeEach(() => {
			injector = Injector.resolveAndCreate([
				MockBackend
			]);
			backend = injector.get(MockBackend);
			response = new Response({ body: LOGO_GLYPH_HTML });
		});
		
		afterEach(() => backend.verifyNoPendingRequests());
		
		it('should append an svg as child of self', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
			let html = '<div class="logo" logo></div>';
			ObservableWrapper.subscribe(backend.connections, (connection: MockConnection) => {
				// console.log(connection);
				connection.mockRespond(response)
			});
			tcb
				.overrideTemplate(Test, html)
				.createAsync(Test)
				.then((rootTC) => {
					rootTC.detectChanges();
					let logo: Element = DOM.querySelector(rootTC.nativeElement, '.logo');
					let prefixSelector = isNativeShadowDOMSupported ? '* /deep/ ' : ''; // soon use '>>>' https://www.chromestatus.com/features/6750456638341120
					// console.log(logo.firstChild, prefixSelector);
					// expect(logo.querySelector(prefixSelector + 'svg')).not.toBe(null);
					async.done();
				});
		}));
	});
示例#6
0
      describe("dirty", () => {
        var c, g;

        beforeEach(() => {
          c = new Control('value');
          g = new ControlGroup({"one": c});
        });

        it("should be false after creating a control", () => { expect(g.dirty).toEqual(false); });

        it("should be false after changing the value of the control", () => {
          c.markAsDirty();

          expect(g.dirty).toEqual(true);
        });
      });
示例#7
0
        describe("dirty", () => {
          var c, a;

          beforeEach(() => {
            c = new Control('value');
            a = new ControlArray([c]);
          });

          it("should be false after creating a control", () => { expect(a.dirty).toEqual(false); });

          it("should be false after changing the value of the control", () => {
            c.markAsDirty();

            expect(a.dirty).toEqual(true);
          });
        });
示例#8
0
      describe("updateValue", () => {
        var g, c;
        beforeEach(() => {
          c = new Control("oldValue");
          g = new ControlGroup({"one": c});
        });

        it("should update the value of the control", () => {
          c.updateValue("newValue");
          expect(c.value).toEqual("newValue");
        });

        it("should invoke onChange if it is present", () => {
          var onChange;
          c.registerOnChange((v) => onChange = ["invoked", v]);

          c.updateValue("newValue");

          expect(onChange).toEqual(["invoked", "newValue"]);
        });

        it("should update the parent", () => {
          c.updateValue("newValue");
          expect(g.value).toEqual({"one": "newValue"});
        });

        it("should not update the parent when explicitly specified", () => {
          c.updateValue("newValue", {onlySelf: true});
          expect(g.value).toEqual({"one": "oldValue"});
        });

        it("should fire an event", fakeAsync(() => {
             ObservableWrapper.subscribe(c.valueChanges,
                                         (value) => { expect(value).toEqual("newValue"); });

             c.updateValue("newValue");
             tick();
           }));

        it("should not fire an event when explicitly specified", fakeAsync(() => {
             ObservableWrapper.subscribe(c.valueChanges, (value) => { throw "Should not happen"; });

             c.updateValue("newValue", {emitEvent: false});

             tick();
           }));
      });
  describe('TemplateCloner', () => {
    var cloner: TemplateCloner;
    var bigTemplate: Element;
    var smallTemplate: Element;

    beforeEach(() => {
      cloner = new TemplateCloner(1);
      bigTemplate = DOM.createTemplate('a<div></div>');
      smallTemplate = DOM.createTemplate('a');
    });

    describe('prepareForClone', () => {
      it('should use a reference for small templates',
         () => { expect(cloner.prepareForClone(smallTemplate)).toBe(smallTemplate); });

      it('should use a reference if the max element count is -1', () => {
        cloner = new TemplateCloner(-1);
        expect(cloner.prepareForClone(bigTemplate)).toBe(bigTemplate);
      });

      it('should use a string for big templates', () => {
        expect(cloner.prepareForClone(bigTemplate)).toEqual(DOM.getInnerHTML(bigTemplate));
      });
    });

    describe('cloneTemplate', () => {

      function shouldReturnTemplateContentNodes(template: Element, importIntoDoc: boolean) {
        var clone = cloner.cloneContent(cloner.prepareForClone(template), importIntoDoc);
        expect(clone).not.toBe(DOM.content(template));
        expect(DOM.getText(DOM.firstChild(clone))).toEqual('a');
      }

      it('should return template.content nodes (small template, no import)',
         () => { shouldReturnTemplateContentNodes(smallTemplate, false); });

      it('should return template.content nodes (small template, import)',
         () => { shouldReturnTemplateContentNodes(smallTemplate, true); });

      it('should return template.content nodes (big template, no import)',
         () => { shouldReturnTemplateContentNodes(bigTemplate, false); });

      it('should return template.content nodes (big template, import)',
         () => { shouldReturnTemplateContentNodes(bigTemplate, true); });
    });

  });
 describe('NativeShadowDomStratgey', () => {
   beforeEach(() => {
     var urlResolver = new UrlResolver();
     var styleUrlResolver = new StyleUrlResolver(urlResolver);
     strategy = new NativeShadowDomStrategy(styleUrlResolver);
   });
   it('should attach the view nodes to the shadow root', () => {
     var host = el('<div></div>');
     var nodes = el('<div>view</div>');
     var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null, null), null);
     var view = pv.instantiate(null, null);
     strategy.attachTemplate(host, view);
     var shadowRoot = DOM.getShadowRoot(host);
     expect(isPresent(shadowRoot)).toBeTruthy();
     expect(shadowRoot).toHaveText('view');
   });
 });