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


TypeScript testing_internal.beforeEach函数代码示例

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


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

示例1: describe

  describe('redirects', () => {

    var tcb: TestComponentBuilder;
    var rootTC: ComponentFixture;
    var rtr;

    beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

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


    it('should apply when navigating by URL',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb)
             .then((rtc) => {rootTC = rtc})
             .then((_) => rtr.config([
               new Redirect({path: '/original', redirectTo: ['Hello']}),
               new Route({path: '/redirected', component: HelloCmp, name: 'Hello'})
             ]))
             .then((_) => rtr.navigateByUrl('/original'))
             .then((_) => {
               rootTC.detectChanges();
               expect(rootTC.debugElement.nativeElement).toHaveText('hello');
               expect(location.urlChanges).toEqual(['/redirected']);
               async.done();
             });
       }));


    it('should recognize and apply absolute redirects',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb)
             .then((rtc) => {rootTC = rtc})
             .then((_) => rtr.config([
               new Redirect({path: '/original', redirectTo: ['/Hello']}),
               new Route({path: '/redirected', component: HelloCmp, name: 'Hello'})
             ]))
             .then((_) => rtr.navigateByUrl('/original'))
             .then((_) => {
               rootTC.detectChanges();
               expect(rootTC.debugElement.nativeElement).toHaveText('hello');
               expect(location.urlChanges).toEqual(['/redirected']);
               async.done();
             });
       }));


    it('should recognize and apply relative child redirects',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb)
             .then((rtc) => {rootTC = rtc})
             .then((_) => rtr.config([
               new Redirect({path: '/original', redirectTo: ['./Hello']}),
               new Route({path: '/redirected', component: HelloCmp, name: 'Hello'})
             ]))
             .then((_) => rtr.navigateByUrl('/original'))
             .then((_) => {
               rootTC.detectChanges();
               expect(rootTC.debugElement.nativeElement).toHaveText('hello');
               expect(location.urlChanges).toEqual(['/redirected']);
               async.done();
             });
       }));


    it('should recognize and apply relative parent redirects',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb)
             .then((rtc) => {rootTC = rtc})
             .then((_) => rtr.config([
               new Route({path: '/original/...', component: RedirectToParentCmp}),
               new Route({path: '/redirected', component: HelloCmp, name: 'HelloSib'})
             ]))
             .then((_) => rtr.navigateByUrl('/original/child-redirect'))
             .then((_) => {
               rootTC.detectChanges();
               expect(rootTC.debugElement.nativeElement).toHaveText('hello');
               expect(location.urlChanges).toEqual(['/redirected']);
               async.done();
             });
       }));


    it('should not redirect when redirect is less specific than other matching routes',
       inject([AsyncTestCompleter, Location], (async, location) => {
         compile(tcb)
             .then((rtc) => {rootTC = rtc})
             .then((_) => rtr.config([
               new Route({path: '/foo', component: HelloCmp, name: 'Hello'}),
               new Route({path: '/:param', component: GoodbyeCmp, name: 'Goodbye'}),
               new Redirect({path: '/*rest', redirectTo: ['/Hello']})
             ]))
             .then((_) => rtr.navigateByUrl('/bye'))
             .then((_) => {
               rootTC.detectChanges();
//.........这里部分代码省略.........
开发者ID:Ashok-Pal,项目名称:angular,代码行数:101,代码来源:redirect_route_spec.ts

示例2: describe

    describe('classes', () => {
      var callSomeMethod: o.Statement;

      beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });

      it('should support declaring classes', () => {
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [])))
            .toEqual(['function SomeClass() {', '}'].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, []), ['SomeClass']))
            .toEqual([
              'function SomeClass() {',
              '}',
              `Object.defineProperty(exports, 'SomeClass', { get: function() { return SomeClass; }});`
            ].join('\n'));
        expect(
            emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [])))
            .toEqual([
              'function SomeClass() {',
              '}',
              'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
            ].join('\n'));
      });

      it('should support declaring constructors', () => {
        var superCall = o.SUPER_EXPR.callFn([o.variable('someParam')]).toStmt();
        expect(emitStmt(
                   new o.ClassStmt('SomeClass', null, [], [], new o.ClassMethod(null, [], []), [])))
            .toEqual(['function SomeClass() {', '}'].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
                                        new o.ClassMethod(null, [new o.FnParam('someParam')], []),
                                        [])))
            .toEqual(['function SomeClass(someParam) {', '}'].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [],
                                        new o.ClassMethod(null, [], [superCall]), [])))
            .toEqual([
              'function SomeClass() {',
              '  var self = this;',
              '  SomeSuperClass.call(this, someParam);',
              '}',
              'SomeClass.prototype = Object.create(SomeSuperClass.prototype);'
            ].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [],
                                        new o.ClassMethod(null, [], [callSomeMethod]), [])))
            .toEqual(
                ['function SomeClass() {', '  var self = this;', '  self.someMethod();', '}'].join(
                    '\n'));
      });

      it('should support declaring getters', () => {
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
                                        [new o.ClassGetter('someGetter', [])], null, [])))
            .toEqual([
              'function SomeClass() {',
              '}',
              `Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`,
              `}});`
            ].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [],
                                        [new o.ClassGetter('someGetter', [callSomeMethod])], null,
                                        [])))
            .toEqual([
              'function SomeClass() {',
              '}',
              `Object.defineProperty(SomeClass.prototype, 'someGetter', { get: function() {`,
              `  var self = this;`,
              `  self.someMethod();`,
              `}});`
            ].join('\n'));
      });

      it('should support methods', () => {
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
                                        [new o.ClassMethod('someMethod', [], [])])))
            .toEqual([
              'function SomeClass() {',
              '}',
              'SomeClass.prototype.someMethod = function() {',
              '};'
            ].join('\n'));
        expect(emitStmt(new o.ClassStmt(
                   'SomeClass', null, [], [], null,
                   [new o.ClassMethod('someMethod', [new o.FnParam('someParam')], [])])))
            .toEqual([
              'function SomeClass() {',
              '}',
              'SomeClass.prototype.someMethod = function(someParam) {',
              '};'
            ].join('\n'));
        expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null,
                                        [new o.ClassMethod('someMethod', [], [callSomeMethod])])))
            .toEqual([
              'function SomeClass() {',
              '}',
              'SomeClass.prototype.someMethod = function() {',
              '  var self = this;',
              '  self.someMethod();',
              '};'
            ].join('\n'));
      });
    });
开发者ID:AwelEshetu,项目名称:angular,代码行数:100,代码来源:js_emitter_spec.ts

示例3: describe

  describe('EventEmitter', () => {
    var emitter: EventEmitter;

    beforeEach(() => { emitter = new EventEmitter(); });

    it("should call the next callback", inject([AsyncTestCompleter], (async) => {
         ObservableWrapper.subscribe(emitter, (value) => {
           expect(value).toEqual(99);
           async.done();
         });

         ObservableWrapper.callNext(emitter, 99);
       }));

    it("should call the throw callback", inject([AsyncTestCompleter], (async) => {
         ObservableWrapper.subscribe(emitter, (_) => {}, (error) => {
           expect(error).toEqual("Boom");
           async.done();
         });
         ObservableWrapper.callThrow(emitter, "Boom");
       }));

    it("should work when no throw callback is provided", inject([AsyncTestCompleter], (async) => {
         ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { async.done(); });
         ObservableWrapper.callThrow(emitter, "Boom");
       }));

    it("should call the return callback", inject([AsyncTestCompleter], (async) => {
         ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { async.done(); });

         ObservableWrapper.callReturn(emitter);
       }));

    it("should subscribe to the wrapper asynchronously", () => {
      var called = false;
      ObservableWrapper.subscribe(emitter, (value) => { called = true; });

      ObservableWrapper.callNext(emitter, 99);
      expect(called).toBe(false);
    });

    it('delivers events asynchronously', inject([AsyncTestCompleter], (async) => {
         var e = new EventEmitter();
         var log = [];
         ObservableWrapper.subscribe(e, (x) => {
           log.push(x);
           expect(log).toEqual([1, 3, 2]);
           async.done();
         });
         log.push(1);
         ObservableWrapper.callNext(e, 2);
         log.push(3);
       }));

    it('delivers events synchronously', () => {
      var e = new EventEmitter(false);
      var log = [];
      ObservableWrapper.subscribe(e, (x) => { log.push(x); });
      log.push(1);
      ObservableWrapper.callNext(e, 2);
      log.push(3);
      expect(log).toEqual([1, 2, 3]);
    });

    it('reports whether it has subscribers', () => {
      var e = new EventEmitter(false);
      expect(ObservableWrapper.hasSubscribers(e)).toBe(false);
      ObservableWrapper.subscribe(e, (_) => {});
      expect(ObservableWrapper.hasSubscribers(e)).toBe(true);
    });

    // TODO: vsavkin: add tests cases
    // should call dispose on the subscription if generator returns {done:true}
    // should call dispose on the subscription on throw
    // should call dispose on the subscription on return
  });
开发者ID:hankduan,项目名称:angular,代码行数:76,代码来源:async_spec.ts

示例4: describe

  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,代码行数:65,代码来源:location_spec.ts

示例5: describe

  describe('Router', () => {
    var router, location;

    beforeEachProviders(() => [
      RouteRegistry,
      DirectiveResolver,
      provide(Location, {useClass: SpyLocation}),
      provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
      provide(Router, {useClass: RootRouter})
    ]);


    beforeEach(inject([Router, Location], (rtr, loc) => {
      router = rtr;
      location = loc;
    }));


    it('should navigate based on the initial URL state', inject([AsyncTestCompleter], (async) => {
         var outlet = makeDummyOutlet();

         router.config([new Route({path: '/', component: DummyComponent})])
             .then((_) => router.registerPrimaryOutlet(outlet))
             .then((_) => {
               expect(outlet.spy('activate')).toHaveBeenCalled();
               expect(location.urlChanges).toEqual([]);
               async.done();
             });
       }));

    it('should activate viewports and update URL on navigate',
       inject([AsyncTestCompleter], (async) => {
         var outlet = makeDummyOutlet();

         router.registerPrimaryOutlet(outlet)
             .then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
             .then((_) => router.navigateByUrl('/a'))
             .then((_) => {
               expect(outlet.spy('activate')).toHaveBeenCalled();
               expect(location.urlChanges).toEqual(['/a']);
               async.done();
             });
       }));

    it('should activate viewports and update URL when navigating via DSL',
       inject([AsyncTestCompleter], (async) => {
         var outlet = makeDummyOutlet();

         router.registerPrimaryOutlet(outlet)
             .then((_) => router.config(
                       [new Route({path: '/a', component: DummyComponent, name: 'A'})]))
             .then((_) => router.navigate(['/A']))
             .then((_) => {
               expect(outlet.spy('activate')).toHaveBeenCalled();
               expect(location.urlChanges).toEqual(['/a']);
               async.done();
             });
       }));

    it('should not push a history change on when navigate is called with skipUrlChange',
       inject([AsyncTestCompleter], (async) => {
         var outlet = makeDummyOutlet();

         router.registerPrimaryOutlet(outlet)
             .then((_) => router.config([new Route({path: '/b', component: DummyComponent})]))
             .then((_) => router.navigateByUrl('/b', true))
             .then((_) => {
               expect(outlet.spy('activate')).toHaveBeenCalled();
               expect(location.urlChanges).toEqual([]);
               async.done();
             });
       }));

    // See https://github.com/angular/angular/issues/5590
    // This test is disabled because it is flaky.
    // TODO: bford. make this test not flaky and reenable it.
    xit('should replace history when triggered by a hashchange with a redirect',
        inject([AsyncTestCompleter], (async) => {
          var outlet = makeDummyOutlet();

          router.registerPrimaryOutlet(outlet)
              .then((_) => router.config([
                new Redirect({path: '/a', redirectTo: ['B']}),
                new Route({path: '/b', component: DummyComponent, name: 'B'})
              ]))
              .then((_) => {
                router.subscribe((_) => {
                  expect(location.urlChanges).toEqual(['hash: a', 'replace: /b']);
                  async.done();
                });

                location.simulateHashChange('a');
              });
        }));

    it('should push history when triggered by a hashchange without a redirect',
       inject([AsyncTestCompleter], (async) => {
         var outlet = makeDummyOutlet();

         router.registerPrimaryOutlet(outlet)
//.........这里部分代码省略.........
开发者ID:DarshanKumar89,项目名称:angular,代码行数:101,代码来源:router_spec.ts

示例6: syncRoutesWithoutChildrenWithParams

function syncRoutesWithoutChildrenWithParams() {
  var fixture;
  var tcb;
  var rtr;

  beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

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

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

  it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
       compile(tcb)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config(
                     [new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
           .then((_) => rtr.navigate(['/User', {name: 'brian'}]))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('hello brian');
             async.done();
           });
     }));

  it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
       compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config(
                     [new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
           .then((_) => {
             fixture.detectChanges();
             expect(getHref(getLinkElement(fixture))).toEqual('/user/naomi');
             async.done();
           });
     }));

  it('should navigate from a link click',
     inject([AsyncTestCompleter, Location], (async, location) => {
       compile(tcb, `<a [routerLink]="['User', {name: 'naomi'}]">greet naomi</a> | <router-outlet></router-outlet>`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config(
                     [new Route({path: '/user/:name', component: UserCmp, name: 'User'})]))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('greet naomi | ');

             rtr.subscribe((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('greet naomi | hello naomi');
               expect(location.urlChanges).toEqual(['/user/naomi']);
               async.done();
             });

             clickOnElement(getLinkElement(fixture));
           });
     }));

  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, name: 'User'})]))
           .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();
           });
     }));
}
开发者ID:844496869,项目名称:angular,代码行数:90,代码来源:sync_route_spec_impl.ts

示例7: syncRoutesWithoutChildrenWithoutParams

function syncRoutesWithoutChildrenWithoutParams() {
  var fixture;
  var tcb;
  var rtr;

  beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

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

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

  it('should navigate by link DSL', inject([AsyncTestCompleter], (async) => {
       compile(tcb)
           .then((rtc) => {fixture = rtc})
           .then((_) =>
                     rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
           .then((_) => rtr.navigate(['/Hello']))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('hello');
             async.done();
           });
     }));

  it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
       compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
           .then((rtc) => {fixture = rtc})
           .then((_) =>
                     rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
           .then((_) => {
             fixture.detectChanges();
             expect(getHref(getLinkElement(fixture))).toEqual('/test');
             async.done();
           });
     }));

  it('should navigate from a link click',
     inject([AsyncTestCompleter, Location], (async, location) => {
       compile(tcb, `<a [routerLink]="['Hello']">go to hello</a> | <router-outlet></router-outlet>`)
           .then((rtc) => {fixture = rtc})
           .then((_) =>
                     rtr.config([new Route({path: '/test', component: HelloCmp, name: 'Hello'})]))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('go to hello | ');

             rtr.subscribe((_) => {
               fixture.detectChanges();
               expect(fixture.debugElement.nativeElement).toHaveText('go to hello | hello');
               expect(location.urlChanges).toEqual(['/test']);
               async.done();
             });

             clickOnElement(getLinkElement(fixture));
           });
     }));
}
开发者ID:844496869,项目名称:angular,代码行数:71,代码来源:sync_route_spec_impl.ts

示例8: 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, 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, 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:TedSander,项目名称:angular,代码行数:72,代码来源:change_detector_compiler_spec.ts

示例9: auxRoutes

function auxRoutes() {
  var tcb: TestComponentBuilder;
  var fixture: ComponentFixture;
  var rtr;

  beforeEachProviders(() => TEST_ROUTER_PROVIDERS);

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

  it('should recognize and navigate from the URL', inject([AsyncTestCompleter], (async) => {
       compile(tcb, `main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config([
             new Route({path: '/hello', component: HelloCmp, name: 'Hello'}),
             new AuxRoute({path: '/modal', component: ModalCmp, name: 'Aux'})
           ]))
           .then((_) => rtr.navigateByUrl('/(modal)'))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('main {} | aux {modal}');
             async.done();
           });
     }));

  it('should navigate via the link DSL', inject([AsyncTestCompleter], (async) => {
       compile(tcb, `main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config([
             new Route({path: '/hello', component: HelloCmp, name: 'Hello'}),
             new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'})
           ]))
           .then((_) => rtr.navigate(['/', ['Modal']]))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement).toHaveText('main {} | aux {modal}');
             async.done();
           });
     }));

  it('should generate a link URL', inject([AsyncTestCompleter], (async) => {
       compile(
           tcb,
           `<a [routerLink]="['/', ['Modal']]">open modal</a> | main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config([
             new Route({path: '/hello', component: HelloCmp, name: 'Hello'}),
             new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'})
           ]))
           .then((_) => {
             fixture.detectChanges();
             expect(getHref(getLinkElement(fixture))).toEqual('/(modal)');
             async.done();
           });
     }));

  it('should navigate from a link click',
     inject([AsyncTestCompleter, Location], (async, location) => {
       compile(
           tcb,
           `<a [routerLink]="['/', ['Modal']]">open modal</a> | <a [routerLink]="['/Hello']">hello</a> | main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`)
           .then((rtc) => {fixture = rtc})
           .then((_) => rtr.config([
             new Route({path: '/hello', component: HelloCmp, name: 'Hello'}),
             new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'})
           ]))
           .then((_) => {
             fixture.detectChanges();
             expect(fixture.debugElement.nativeElement)
                 .toHaveText('open modal | hello | main {} | aux {}');

             var navCount = 0;

             rtr.subscribe((_) => {
               navCount += 1;
               fixture.detectChanges();
               if (navCount == 1) {
                 expect(fixture.debugElement.nativeElement)
                     .toHaveText('open modal | hello | main {} | aux {modal}');
                 expect(location.urlChanges).toEqual(['/(modal)']);
                 expect(getHref(getLinkElement(fixture, 0))).toEqual('/(modal)');
                 expect(getHref(getLinkElement(fixture, 1))).toEqual('/hello(modal)');

                 // click on primary route link
                 clickOnElement(getLinkElement(fixture, 1));
               } else if (navCount == 2) {
                 expect(fixture.debugElement.nativeElement)
                     .toHaveText('open modal | hello | main {hello} | aux {modal}');
                 expect(location.urlChanges).toEqual(['/(modal)', '/hello(modal)']);
                 expect(getHref(getLinkElement(fixture, 0))).toEqual('/hello(modal)');
                 expect(getHref(getLinkElement(fixture, 1))).toEqual('/hello(modal)');
                 async.done();
               } else {
                 throw new BaseException(`Unexpected route change #${navCount}`);
               }
             });

             clickOnElement(getLinkElement(fixture));
//.........这里部分代码省略.........
开发者ID:bet4vlom,项目名称:angular,代码行数:101,代码来源:aux_route_spec_impl.ts

示例10: describe

  describe('SelectorMatcher', () => {
    var matcher, selectableCollector, s1, s2, s3, s4;
    var matched: any[];

    function reset() { matched = []; }

    beforeEach(() => {
      reset();
      s1 = s2 = s3 = s4 = null;
      selectableCollector = (selector, context) => {
        matched.push(selector);
        matched.push(context);
      };
      matcher = new SelectorMatcher();
    });

    it('should select by element name case insensitive', () => {
      matcher.addSelectables(s1 = CssSelector.parse('someTag'), 1);

      expect(matcher.match(CssSelector.parse('SOMEOTHERTAG')[0], selectableCollector))
          .toEqual(false);
      expect(matched).toEqual([]);

      expect(matcher.match(CssSelector.parse('SOMETAG')[0], selectableCollector)).toEqual(true);
      expect(matched).toEqual([s1[0], 1]);
    });

    it('should select by class name case insensitive', () => {
      matcher.addSelectables(s1 = CssSelector.parse('.someClass'), 1);
      matcher.addSelectables(s2 = CssSelector.parse('.someClass.class2'), 2);

      expect(matcher.match(CssSelector.parse('.SOMEOTHERCLASS')[0], selectableCollector))
          .toEqual(false);
      expect(matched).toEqual([]);

      expect(matcher.match(CssSelector.parse('.SOMECLASS')[0], selectableCollector)).toEqual(true);
      expect(matched).toEqual([s1[0], 1]);

      reset();
      expect(matcher.match(CssSelector.parse('.someClass.class2')[0], selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1, s2[0], 2]);
    });

    it('should select by attr name case insensitive independent of the value', () => {
      matcher.addSelectables(s1 = CssSelector.parse('[someAttr]'), 1);
      matcher.addSelectables(s2 = CssSelector.parse('[someAttr][someAttr2]'), 2);

      expect(matcher.match(CssSelector.parse('[SOMEOTHERATTR]')[0], selectableCollector))
          .toEqual(false);
      expect(matched).toEqual([]);

      expect(matcher.match(CssSelector.parse('[SOMEATTR]')[0], selectableCollector)).toEqual(true);
      expect(matched).toEqual([s1[0], 1]);

      reset();
      expect(matcher.match(CssSelector.parse('[SOMEATTR=someValue]')[0], selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1]);

      reset();
      expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1, s2[0], 2]);

      reset();
      expect(matcher.match(CssSelector.parse('[someAttr=someValue][someAttr2]')[0],
                           selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1, s2[0], 2]);

      reset();
      expect(matcher.match(CssSelector.parse('[someAttr2][someAttr=someValue]')[0],
                           selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1, s2[0], 2]);

      reset();
      expect(matcher.match(CssSelector.parse('[someAttr2=someValue][someAttr]')[0],
                           selectableCollector))
          .toEqual(true);
      expect(matched).toEqual([s1[0], 1, s2[0], 2]);
    });

    it('should select by attr name only once if the value is from the DOM', () => {
      matcher.addSelectables(s1 = CssSelector.parse('[some-decor]'), 1);

      var elementSelector = new CssSelector();
      var element = el('<div attr></div>');
      var empty = DOM.getAttribute(element, 'attr');
      elementSelector.addAttribute('some-decor', empty);
      matcher.match(elementSelector, selectableCollector);
      expect(matched).toEqual([s1[0], 1]);
    });

    it('should select by attr name and value case insensitive', () => {
      matcher.addSelectables(s1 = CssSelector.parse('[someAttr=someValue]'), 1);

      expect(matcher.match(CssSelector.parse('[SOMEATTR=SOMEOTHERATTR]')[0], selectableCollector))
          .toEqual(false);
//.........这里部分代码省略.........
开发者ID:TedSander,项目名称:angular,代码行数:101,代码来源:selector_spec.ts


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