当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing_internal.describe函数代码示例

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


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

示例1: main

export function main() {
  describe('WebWorkerPlatformLocation', () => {
    var uiBus: MessageBus = null;
    var workerBus: MessageBus = null;
    var broker: any = null;
    var TEST_LOCATION = new LocationType(
        'http://www.example.com', 'http', 'example.com', 'example.com', '80', '/', '', '',
        'http://www.example.com');


    function createWebWorkerPlatformLocation(loc: LocationType): WebWorkerPlatformLocation {
      broker.spy('runOnService').andCallFake((args: UiArguments, returnType: Type) => {
        if (args.method === 'getLocation') {
          return PromiseWrapper.resolve(loc);
        }
      });
      var factory = new MockMessageBrokerFactory(broker);
      return new WebWorkerPlatformLocation(factory, workerBus, null);
    }

    function testPushOrReplaceState(pushState: boolean) {
      let platformLocation = createWebWorkerPlatformLocation(null);
      const TITLE = 'foo';
      const URL = 'http://www.example.com/foo';
      expectBrokerCall(broker, pushState ? 'pushState' : 'replaceState', [null, TITLE, URL]);
      if (pushState) {
        platformLocation.pushState(null, TITLE, URL);
      } else {
        platformLocation.replaceState(null, TITLE, URL);
      }
    }

    beforeEach(() => {
      var buses = createPairedMessageBuses();
      uiBus = buses.ui;
      workerBus = buses.worker;
      workerBus.initChannel('ng-Router');
      uiBus.initChannel('ng-Router');
      broker = new SpyMessageBroker();
    });

    it('should throw if getBaseHrefFromDOM is called', () => {
      let platformLocation = createWebWorkerPlatformLocation(null);
      expect(() => platformLocation.getBaseHrefFromDOM()).toThrowError();
    });

    it('should get location on init', () => {
      let platformLocation = createWebWorkerPlatformLocation(null);
      expectBrokerCall(broker, 'getLocation');
      platformLocation.init();
    });

    it('should throw if set pathname is called before init finishes', () => {
      let platformLocation = createWebWorkerPlatformLocation(null);
      platformLocation.init();
      expect(() => platformLocation.pathname = 'TEST').toThrowError();
    });

    it('should send pathname to render thread', inject([AsyncTestCompleter], (async) => {
         let platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION);
         platformLocation.init().then((_) => {
           let PATHNAME = '/test';
           expectBrokerCall(broker, 'setPathname', [PATHNAME]);
           platformLocation.pathname = PATHNAME;
           async.done();
         });
       }));

    it('should send pushState to render thread', () => { testPushOrReplaceState(true); });

    it('should send replaceState to render thread', () => { testPushOrReplaceState(false); });
  });
}
开发者ID:LordBinary,项目名称:angular,代码行数:73,代码来源:platform_location_spec.ts

示例2: main

export function main() {
  describe('navigation', () => {

    var tcb: TestComponentBuilder;
    var fixture: ComponentFixture;
    var rtr;

    beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

    beforeEach(inject([TestComponentBuilder, Router], (tcBuilder, router) => {
      tcb = tcBuilder;
      rtr = router;
      childCmpInstanceCount = 0;
      cmpInstanceCount = 0;
    }));

    it('should work in a simple case', inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/test', component: HelloCmp})]))
             .then((_) => rtr.navigateByUrl('/test'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('hello');
               async.done();
             });
       }));


    it('should navigate between components with different parameters',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/user/:name', component: UserCmp})]))
             .then((_) => rtr.navigateByUrl('/user/brian'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('hello brian');
             })
             .then((_) => rtr.navigateByUrl('/user/igor'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('hello igor');
               async.done();
             });
       }));

    it('should navigate to child routes', inject([AsyncTestCompleter], (async) => {
         compile(tcb, 'outer { <router-outlet></router-outlet> }')
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
             .then((_) => rtr.navigateByUrl('/a/b'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
               async.done();
             });
       }));

    it('should navigate to child routes that capture an empty path',
       inject([AsyncTestCompleter], (async) => {

         compile(tcb, 'outer { <router-outlet></router-outlet> }')
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/a/...', component: ParentCmp})]))
             .then((_) => rtr.navigateByUrl('/a'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
               async.done();
             });
       }));

    it('should navigate to child routes when the root component has an empty path',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb, 'outer { <router-outlet></router-outlet> }')
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: ParentCmp})]))
             .then((_) => rtr.navigateByUrl('/b'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
               expect(location.urlChanges).toEqual(['/b']);
               async.done();
             });
       }));

    it('should navigate to child routes of async routes', inject([AsyncTestCompleter], (async) => {
         compile(tcb, 'outer { <router-outlet></router-outlet> }')
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new AsyncRoute({path: '/a/...', loader: parentLoader})]))
             .then((_) => rtr.navigateByUrl('/a/b'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('outer { inner { hello } }');
               async.done();
             });
       }));

    it('should reuse common parent components', inject([AsyncTestCompleter], (async) => {
//.........这里部分代码省略.........
开发者ID:Ashok-Pal,项目名称:angular,代码行数:101,代码来源:navigation_spec.ts

示例3: describe

  describe('ChangeDetectorCompiler', () => {
    beforeEachBindings(() => TEST_PROVIDERS);

    var parser: TemplateParser;
    var compiler: ChangeDetectionCompiler;

    beforeEach(inject([TemplateParser, ChangeDetectionCompiler], (_parser, _compiler) => {
      parser = _parser;
      compiler = _compiler;
    }));

    describe('compileComponentRuntime', () => {
      function detectChanges(compiler: ChangeDetectionCompiler, template: string,
                             directives: CompileDirectiveMetadata[] = CONST_EXPR([])): string[] {
        var type =
            new CompileTypeMetadata({name: stringify(SomeComponent), moduleUrl: THIS_MODULE_URL});
        var parsedTemplate = parser.parse(template, directives, 'TestComp');
        var factories =
            compiler.compileComponentRuntime(type, ChangeDetectionStrategy.Default, parsedTemplate);
        return testChangeDetector(factories[0]);
      }

      describe('no jit', () => {
        beforeEachBindings(() => [
          provide(ChangeDetectorGenConfig,
                  {useValue: new ChangeDetectorGenConfig(true, true, false, false)})
        ]);
        it('should watch element properties', () => {
          expect(detectChanges(compiler, '<div [el-prop]="someProp">'))
              .toEqual(['elementProperty(elProp)=someValue']);
        });
      });

      describe('jit', () => {
        beforeEachBindings(() => [
          provide(ChangeDetectorGenConfig,
                  {useValue: new ChangeDetectorGenConfig(true, true, false, true)})
        ]);
        it('should watch element properties', () => {
          expect(detectChanges(compiler, '<div [el-prop]="someProp">'))
              .toEqual(['elementProperty(elProp)=someValue']);
        });

      });


    });

    describe('compileComponentCodeGen', () => {
      function detectChanges(compiler: ChangeDetectionCompiler, template: string,
                             directives: CompileDirectiveMetadata[] = CONST_EXPR([])):
          Promise<string[]> {
        var type =
            new CompileTypeMetadata({name: stringify(SomeComponent), moduleUrl: THIS_MODULE_URL});
        var parsedTemplate = parser.parse(template, directives, 'TestComp');
        var sourceExpressions =
            compiler.compileComponentCodeGen(type, ChangeDetectionStrategy.Default, parsedTemplate);
        var testableModule = createTestableModule(sourceExpressions, 0).getSourceWithImports();
        return evalModule(testableModule.source, testableModule.imports, null);
      }

      it('should watch element properties', inject([AsyncTestCompleter], (async) => {
           detectChanges(compiler, '<div [el-prop]="someProp">')
               .then((value) => {
                 expect(value).toEqual(['elementProperty(elProp)=someValue']);
                 async.done();
               });

         }));
    });

  });
开发者ID:,项目名称:,代码行数:72,代码来源:

示例4: describe

  describe("NgZone", () => {

    function createZone(enableLongStackTrace) {
      var zone = new NgZone({enableLongStackTrace: enableLongStackTrace});
      zone.overrideOnTurnStart(_log.fn('onTurnStart'));
      zone.overrideOnTurnDone(_log.fn('onTurnDone'));
      return zone;
    }

    beforeEach(() => {
      _log = new Log();
      _errors = [];
      _traces = [];
    });

    describe('long stack trace', () => {
      beforeEach(() => { _zone = createZone(true); });

      commonTests();

      it('should produce long stack traces', inject([AsyncTestCompleter], (async) => {
           macroTask(() => {
             _zone.overrideOnErrorHandler(logError);
             var c: PromiseCompleter<any> = PromiseWrapper.completer();

             _zone.run(() => {
               TimerWrapper.setTimeout(() => {
                 TimerWrapper.setTimeout(() => {
                   c.resolve(null);
                   throw new BaseException('ccc');
                 }, 0);
               }, 0);
             });

             c.promise.then((_) => {
               expect(_traces.length).toBe(1);
               expect(_traces[0].length).toBeGreaterThan(1);
               async.done();
             });
           });
         }), testTimeout);

      it('should produce long stack traces (when using microtasks)',
         inject([AsyncTestCompleter], (async) => {
           macroTask(() => {
             _zone.overrideOnErrorHandler(logError);
             var c: PromiseCompleter<any> = PromiseWrapper.completer();

             _zone.run(() => {
               microTask(() => {
                 microTask(() => {
                   c.resolve(null);
                   throw new BaseException("ddd");
                 });
               });
             });

             c.promise.then((_) => {
               expect(_traces.length).toBe(1);
               expect(_traces[0].length).toBeGreaterThan(1);
               async.done();
             });
           });
         }), testTimeout);
    });

    describe('short stack trace', () => {
      beforeEach(() => { _zone = createZone(false); });

      commonTests();

      it('should disable long stack traces', inject([AsyncTestCompleter], (async) => {
           macroTask(() => {
             _zone.overrideOnErrorHandler(logError);
             var c: PromiseCompleter<any> = PromiseWrapper.completer();

             _zone.run(() => {
               TimerWrapper.setTimeout(() => {
                 TimerWrapper.setTimeout(() => {
                   c.resolve(null);
                   throw new BaseException('ccc');
                 }, 0);
               }, 0);
             });

             c.promise.then((_) => {
               expect(_traces.length).toBe(1);
               expect(_traces[0].length).toEqual(1);
               async.done();
             });
           });
         }), testTimeout);
    });
  });
开发者ID:Ashok-Pal,项目名称:angular,代码行数:94,代码来源:ng_zone_DEPRECATED_spec.ts

示例5: main

export function main() {

  describe('ContactComponent', () => {

    let contactService: ContactService;

    beforeEach(() => {

      contactService = new ContactService(null);

      spyOn(contactService, 'find').and.callFake(() => Observable.of(contacts));

      spyOn(contactService, 'findOneById').and.callFake((id: string) =>
        Observable.of(contacts.find(it => it._id === id))
      );

      spyOn(contactService, 'removeOneById').and.callFake((id: string) => {
        let pos: number;
        for (let i = 0; i < contacts.length; ++i) {
          if (contacts[i]._id === id) {
            pos = i;
            break;
          }
        }
        return Observable.of(contacts.splice(pos, 1));
      });
    });


    it('should work',
      inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
        tcb.overrideProviders(ContactComponent, [provide(ContactService, { useValue: contactService })])
          .createAsync(ContactComponent).then((fixture) => {

            fixture.detectChanges();

            const cmp: ContactComponent = fixture.componentInstance;

            const compiled = fixture.debugElement.nativeElement;
            expect(compiled.querySelector('h2').textContent).toEqual('Contacts!');

            const itemsSelector = 'tbody tr';

            function obtainContactsLenght() {
              return compiled.querySelectorAll(itemsSelector).length;
            }

            const originalLength = obtainContactsLenght();
            let newLength = originalLength;
            
            expect(originalLength).toBeGreaterThan(0);            
            expect(originalLength).toBe(contacts.length);

            const existingContact = ObjectUtil.clone(contacts[0]);

            cmp.select(existingContact._id);

            fixture.detectChanges();

            const selectedContact = cmp.selectedContact;

            expect(selectedContact._id).toBe(existingContact._id);
            expect(selectedContact.name).toBe(existingContact.name);

            cmp.remove(new Event('mock'), existingContact);

            fixture.detectChanges();

            newLength--;

            expect(obtainContactsLenght()).toBe(newLength);

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

  });
}
开发者ID:mailightkun,项目名称:angular2-minimalist-starter,代码行数:78,代码来源:contact.component_spec.ts

示例6: describe

  describe('String', () => {
    var s;

    describe('slice', () => {
      beforeEach(() => { s = 'abcdefghij'; });

      it('should return the whole string if neither start nor end are specified',
         () => { expect(StringWrapper.slice(s)).toEqual('abcdefghij'); });

      it('should return up to the end if end is not specified',
         () => { expect(StringWrapper.slice(s, 1)).toEqual('bcdefghij'); });

      it('should support negative start',
         () => { expect(StringWrapper.slice(s, -1)).toEqual('j'); });

      it('should support negative end',
         () => { expect(StringWrapper.slice(s, -3, -1)).toEqual('hi'); });

      it('should return empty string if start is greater than end', () => {
        expect(StringWrapper.slice(s, 4, 2)).toEqual('');
        expect(StringWrapper.slice(s, -2, -4)).toEqual('');
      });
    });

    describe('stripLeft', () => {
      it('should strip the first character of the string if it matches the provided input', () => {
        var input = '~angular2 is amazing';
        var expectedOutput = 'angular2 is amazing';

        expect(StringWrapper.stripLeft(input, '~')).toEqual(expectedOutput);
      });

      it('should keep stripping characters from the start until the first unmatched character',
         () => {
           var input = '#####hello';
           var expectedOutput = 'hello';
           expect(StringWrapper.stripLeft(input, '#')).toEqual(expectedOutput);
         });

      it('should not alter the provided input if the first character does not match the provided input',
         () => {
           var input = '+angular2 is amazing';
           expect(StringWrapper.stripLeft(input, '*')).toEqual(input);
         });

      it('should not do any alterations when an empty string or null value is passed in', () => {
        expect(StringWrapper.stripLeft('', 'S')).toEqual('');
        expect(StringWrapper.stripLeft(null, 'S')).toEqual(null);
      });
    });

    describe('stripRight', () => {
      it('should strip the first character of the string if it matches the provided input', () => {
        var input = 'angular2 is amazing!';
        var expectedOutput = 'angular2 is amazing';

        expect(StringWrapper.stripRight(input, '!')).toEqual(expectedOutput);
      });

      it('should not alter the provided input if the first character does not match the provided input',
         () => {
           var input = 'angular2 is amazing+';

           expect(StringWrapper.stripRight(input, '*')).toEqual(input);
         });

      it('should keep stripping characters from the end until the first unmatched character',
         () => {
           var input = 'hi&!&&&&&';
           var expectedOutput = 'hi&!';
           expect(StringWrapper.stripRight(input, '&')).toEqual(expectedOutput);
         });

      it('should not do any alterations when an empty string or null value is passed in', () => {
        expect(StringWrapper.stripRight('', 'S')).toEqual('');
        expect(StringWrapper.stripRight(null, 'S')).toEqual(null);
      });
    });

    describe('resolveEnumToken', () => {
      it('should resolve a token given an enum and index values', () => {
        var token = UsefulEnum.MyToken;
        expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyToken');

        token = UsefulEnum.MyOtherToken;
        expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyOtherToken');
      });
    });

    describe('hasConstructor', () => {
      it('should be true when the type matches',
         () => { expect(hasConstructor(new MySuperclass(), MySuperclass)).toEqual(true); });

      it('should be false for subtypes',
         () => { expect(hasConstructor(new MySubclass(), MySuperclass)).toEqual(false); });
    });
  });
开发者ID:LordBinary,项目名称:angular,代码行数:97,代码来源:lang_spec.ts

示例7: main

export function main() {
  describe('Router lifecycle hooks', () => {

    var tcb: TestComponentBuilder;
    var fixture: ComponentFixture;
    var rtr: Router;

    beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

    beforeEach(inject(
        [TestComponentBuilder, Router], (tcBuilder: TestComponentBuilder, router: Router) => {
          tcb = tcBuilder;
          rtr = router;
          cmpInstanceCount = 0;
          log = [];
          eventBus = new EventEmitter();
        }));

    it('should call the routerOnActivate hook', inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-activate'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('activate cmp');
               expect(log).toEqual(['activate: null -> /on-activate']);
               async.done();
             });
       }));

    it('should wait for a parent component\'s routerOnActivate hook to resolve before calling its child\'s',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => {
               ObservableWrapper.subscribe<string>(eventBus, (ev) => {
                 if (ev.startsWith('parent activate')) {
                   completer.resolve(true);
                 }
               });
               rtr.navigateByUrl('/parent-activate/child-activate').then((_) => {
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('parent {activate cmp}');
                 expect(log).toEqual([
                   'parent activate: null -> /parent-activate', 'activate: null -> /child-activate'
                 ]);
                 async.done();
               });
             });
       }));

    it('should call the routerOnDeactivate hook', inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-deactivate'))
             .then((_) => rtr.navigateByUrl('/a'))
             .then((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('A');
               expect(log).toEqual(['deactivate: /on-deactivate -> /a']);
               async.done();
             });
       }));

    it('should wait for a child component\'s routerOnDeactivate hook to resolve before calling its parent\'s',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/parent-deactivate/child-deactivate'))
             .then((_) => {
               ObservableWrapper.subscribe<string>(eventBus, (ev) => {
                 if (ev.startsWith('deactivate')) {
                   completer.resolve(true);
                   fixture.detectChanges();
                   expect(fixture.debugElement.nativeElement).toHaveText('parent {deactivate cmp}');
                 }
               });
               rtr.navigateByUrl('/a').then((_) => {
                 fixture.detectChanges();
                 expect(fixture.debugElement.nativeElement).toHaveText('A');
                 expect(log).toEqual([
                   'deactivate: /child-deactivate -> null',
                   'parent deactivate: /parent-deactivate -> /a'
                 ]);
                 async.done();
               });
             });
       }));

    it('should reuse a component when the routerCanReuse hook returns true',
       inject([AsyncTestCompleter], (async) => {
         compile(tcb)
             .then((rtc) => {fixture = rtc})
             .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
             .then((_) => rtr.navigateByUrl('/on-reuse/1/a'))
             .then((_) => {
//.........这里部分代码省略.........
开发者ID:LordBinary,项目名称:angular,代码行数:101,代码来源:lifecycle_hook_spec.ts

示例8: main

export function main() {
  describe('Location', () => {

    var locationStrategy, location;

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

    beforeEach(makeLocation);

    it('should not prepend urls with starting slash when an empty URL is provided',
       () => { expect(location.prepareExternalUrl('')).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.prepareExternalUrl('/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 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 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');
    });

    it('should incorporate the provided query values into the location change', () => {
      var locationStrategy = new MockLocationStrategy();
      var location = new Location(locationStrategy);

      location.go('/home', "key=value");
      expect(location.path()).toEqual("/home?key=value");
    });
  });
}
开发者ID:Ashok-Pal,项目名称:angular,代码行数:67,代码来源:location_spec.ts

示例9: describe

  describe('chrome driver extension', () => {
    var CHROME44_USER_AGENT =
        '"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.0 Safari/537.36"';
    var CHROME45_USER_AGENT =
        '"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2499.0 Safari/537.36"';

    var log;
    var extension;

    var blinkEvents = new TraceEventFactory('blink.console', 'pid0');
    var v8Events = new TraceEventFactory('v8', 'pid0');
    var v8EventsOtherProcess = new TraceEventFactory('v8', 'pid1');
    var chromeTimelineEvents =
        new TraceEventFactory('disabled-by-default-devtools.timeline', 'pid0');
    var chrome45TimelineEvents = new TraceEventFactory('devtools.timeline', 'pid0');
    var chromeTimelineV8Events = new TraceEventFactory('devtools.timeline,v8', 'pid0');
    var chromeBlinkTimelineEvents = new TraceEventFactory('blink,devtools.timeline', 'pid0');
    var chromeBlinkUserTimingEvents = new TraceEventFactory('blink.user_timing', 'pid0');
    var benchmarkEvents = new TraceEventFactory('benchmark', 'pid0');
    var normEvents = new TraceEventFactory('timeline', 'pid0');

    function createExtension(perfRecords = null, userAgent = null,
                             messageMethod = 'Tracing.dataCollected') {
      if (isBlank(perfRecords)) {
        perfRecords = [];
      }
      if (isBlank(userAgent)) {
        userAgent = CHROME44_USER_AGENT;
      }
      log = [];
      extension = Injector.resolveAndCreate([
                            ChromeDriverExtension.BINDINGS,
                            bind(WebDriverAdapter)
                                .toValue(new MockDriverAdapter(log, perfRecords, messageMethod)),
                            bind(Options.USER_AGENT).toValue(userAgent)
                          ])
                      .get(ChromeDriverExtension);
      return extension;
    }

    it('should force gc via window.gc()', inject([AsyncTestCompleter], (async) => {
         createExtension().gc().then((_) => {
           expect(log).toEqual([['executeScript', 'window.gc()']]);
           async.done();
         });
       }));

    it('should mark the timeline via console.time()', inject([AsyncTestCompleter], (async) => {
         createExtension()
             .timeBegin('someName')
             .then((_) => {
               expect(log).toEqual([['executeScript', `console.time('someName');`]]);
               async.done();
             });
       }));

    it('should mark the timeline via console.timeEnd()', inject([AsyncTestCompleter], (async) => {
         createExtension()
             .timeEnd('someName')
             .then((_) => {
               expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
               async.done();
             });
       }));

    it('should mark the timeline via console.time() and console.timeEnd()',
       inject([AsyncTestCompleter], (async) => {
         createExtension()
             .timeEnd('name1', 'name2')
             .then((_) => {
               expect(log)
                   .toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
               async.done();
             });
       }));

    describe('readPerfLog Chrome44', () => {
      it('should normalize times to ms and forward ph and pid event properties',
         inject([AsyncTestCompleter], (async) => {
           createExtension([chromeTimelineEvents.complete('FunctionCall', 1100, 5500, null)])
               .readPerfLog()
               .then((events) => {
                 expect(events).toEqual([
                   normEvents.complete('script', 1.1, 5.5, null),
                 ]);
                 async.done();
               });
         }));

      it('should normalize "tdur" to "dur"', inject([AsyncTestCompleter], (async) => {
           var event = chromeTimelineEvents.create('X', 'FunctionCall', 1100, null);
           event['tdur'] = 5500;
           createExtension([event]).readPerfLog().then((events) => {
             expect(events).toEqual([
               normEvents.complete('script', 1.1, 5.5, null),
             ]);
             async.done();
           });
         }));

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

示例10: describe

  describe('DirectiveNormalizer', () => {
    var dirType: CompileTypeMetadata;

    beforeEachProviders(() => TEST_PROVIDERS);

    beforeEach(() => { dirType = new CompileTypeMetadata({name: 'SomeComp'}); });

    describe('loadTemplate', () => {
      describe('inline template', () => {
        it('should store the template',
           inject([AsyncTestCompleter, DirectiveNormalizer],
                  (async, normalizer: DirectiveNormalizer) => {
                    normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({
                                                   encapsulation: null,
                                                   template: 'a',
                                                   templateUrl: null,
                                                   styles: [],
                                                   styleUrls: ['test.css'],
                                                   baseUrl: 'package:some/module/a.js'
                                                 }))
                        .then((template: CompileTemplateMetadata) => {
                          expect(template.template).toEqual('a');
                          expect(template.templateUrl).toEqual('package:some/module/a.js');
                          async.done();
                        });
                  }));

        it('should resolve styles on the annotation against the baseUrl',
           inject([AsyncTestCompleter, DirectiveNormalizer],
                  (async, normalizer: DirectiveNormalizer) => {
                    normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({
                                                   encapsulation: null,
                                                   template: '',
                                                   templateUrl: null,
                                                   styles: [],
                                                   styleUrls: ['test.css'],
                                                   baseUrl: 'package:some/module/a.js'
                                                 }))
                        .then((template: CompileTemplateMetadata) => {
                          expect(template.styleUrls).toEqual(['package:some/module/test.css']);
                          async.done();
                        });
                  }));

        it('should resolve styles in the template against the baseUrl',
           inject([AsyncTestCompleter, DirectiveNormalizer],
                  (async, normalizer: DirectiveNormalizer) => {
                    normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({
                                                   encapsulation: null,
                                                   template: '<style>@import test.css</style>',
                                                   templateUrl: null,
                                                   styles: [],
                                                   styleUrls: [],
                                                   baseUrl: 'package:some/module/a.js'
                                                 }))
                        .then((template: CompileTemplateMetadata) => {
                          expect(template.styleUrls).toEqual(['package:some/module/test.css']);
                          async.done();
                        });
                  }));
      });

      describe('templateUrl', () => {

        it('should load a template from a url that is resolved against baseUrl',
           inject([AsyncTestCompleter, DirectiveNormalizer, XHR],
                  (async, normalizer: DirectiveNormalizer, xhr: MockXHR) => {
                    xhr.expect('package:some/module/sometplurl.html', 'a');
                    normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({
                                                   encapsulation: null,
                                                   template: null,
                                                   templateUrl: 'sometplurl.html',
                                                   styles: [],
                                                   styleUrls: ['test.css'],
                                                   baseUrl: 'package:some/module/a.js'
                                                 }))
                        .then((template: CompileTemplateMetadata) => {
                          expect(template.template).toEqual('a');
                          expect(template.templateUrl)
                              .toEqual('package:some/module/sometplurl.html');
                          async.done();
                        });
                    xhr.flush();
                  }));

        it('should resolve styles on the annotation against the baseUrl',
           inject([AsyncTestCompleter, DirectiveNormalizer, XHR],
                  (async, normalizer: DirectiveNormalizer, xhr: MockXHR) => {
                    xhr.expect('package:some/module/tpl/sometplurl.html', '');
                    normalizer.normalizeTemplate(dirType, new CompileTemplateMetadata({
                                                   encapsulation: null,
                                                   template: null,
                                                   templateUrl: 'tpl/sometplurl.html',
                                                   styles: [],
                                                   styleUrls: ['test.css'],
                                                   baseUrl: 'package:some/module/a.js'
                                                 }))
                        .then((template: CompileTemplateMetadata) => {
                          expect(template.styleUrls).toEqual(['package:some/module/test.css']);
                          async.done();
//.........这里部分代码省略.........
开发者ID:844496869,项目名称:angular,代码行数:101,代码来源:directive_normalizer_spec.ts


注:本文中的angular2/testing_internal.describe函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。