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


TypeScript testing.describe函数代码示例

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


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

示例1: describe

import { DegreesPipe } from '../../index';
        
import {describe, it, beforeEach, expect} from 'angular2/testing';

describe('DegreesPipe', () => {
    
    let pipe: DegreesPipe;
    
    beforeEach(() => {
       pipe = new DegreesPipe(); 
    });
    
    
    it ('Should transfrom the radians to degrees', () => {
       
       const radians = Math.PI;
       expect(pipe.transform(radians)).toEqual(180);
        
    });
    
   
});
开发者ID:SamGraber,项目名称:angular-pipes,代码行数:22,代码来源:degrees.pipe.spec.ts

示例2: describe

describe("reducer: containers > applicationReducer", () => {
    describe("case CONTAINER_APPLICATION_ENABLE_BUSY_FLAG", () => {
        it("should return a new applicationstate with the isBusyflag to true", () => {
            let initialState: ApplicationContainerState = {
                isBusy: false
            };
            let changedState: ApplicationContainerState = applicationReducer(initialState, {type: CONTAINER_APPLICATION_ENABLE_BUSY_FLAG});
            expect(initialState).not.toBe(changedState);
            expect(changedState.isBusy).toBe(true);
        });
    });
    describe("case CONTAINER_APPLICATION_DISABLE_BUSY_FLAG", () => {
        it("should return a new applicationstate with the isBusyflag to true", () => {
            let initialState: ApplicationContainerState = {
                isBusy: false
            };
            let changedState: ApplicationContainerState = applicationReducer(initialState, {type: CONTAINER_APPLICATION_DISABLE_BUSY_FLAG});
            expect(initialState).not.toBe(changedState);
            expect(changedState.isBusy).toBe(false);
        });
    });
    describe("case default", () => {
        it("should return the exact same reference as before", () => {
            let initialState: ApplicationContainerState = {
                isBusy: false
            };
            let changedState: ApplicationContainerState = applicationReducer(initialState, {type: null});
            expect(changedState).toBe(initialState);
        });
    });
});
开发者ID:FritzH321,项目名称:winecellar,代码行数:31,代码来源:applicationReducer.spec.ts

示例3: describe

describe('Bundles', () => {

  beforeEachProviders(() => [
    provide(NO_LOGIN, {useValue: true}),
    provide(BaseService, {useClass: MockbaseService}), 
    DataService,
  ]);

  let tcb;
  let fix;
  let element;
  let comp: BundlesComponent; 
  let node;
  
  function checkTable(_rows: number, _cols: number) {
    node = element.querySelectorAll('#data')[0];
    expect(node.nodeName).toBe("TABLE");
    expect(node.rows.length).toBe(_rows);
    expect(node.rows[0].cells.length).toBe(_cols);
    return node;
  }

  function cell(_table, _row: number, _col: number) {
    return _table.rows[_row].cells[_col].textContent.trim();
  }

  it('renders and works fine', inject([TestComponentBuilder], (_tcb: TCB) => {

    return _tcb.createAsync(BundlesComponent).then((_fix: CF) => {
      tcb = _tcb;
      fix = _fix;
      element = fix.nativeElement;
      comp = fix.componentRef.instance; 
      expect(true).toBe(true);
      //HACK: A hack to wait for all to be loaded
      return gap().then(()=> {

        fix.detectChanges();
        //insane sanity check
        expect(element.querySelectorAll('div').length).toBe(2);
        //Should be DAY by default
        expect(comp.isDay()).toBe(true);
        fix.detectChanges();
        
        node = element.querySelectorAll('#addFarm')[0];
        expect(node).not.toBe(null);
        expect(node.textContent).toBe("+");
        node = element.querySelectorAll('#addPlant')[0];
        expect(node).not.toBe(null);
        expect(node.textContent).toBe("+");     

        let f = "farm2";
        let p = "plant5";
        node = checkTable(7, 4);
        expect(cell(node, 0, 2)).toBe(f);
        expect(cell(node, 5, 0)).toBe(p);

        let q = 13;
        comp.addHarvestInternal(f, p, q);
        fix.detectChanges();

        node = checkTable(7, 4);
        expect(cell(node, 5, 2)).toBe(""+q);
        expect(cell(node, 1, 2)).toBe(""+q);
        expect(cell(node, 1, 3)).toBe(""+q);
        expect(cell(node, 5, 3)).toBe(""+q);
        expect(cell(node, 6, 2)).toBe(""+q);
        expect(cell(node, 6, 3)).toBe(""+q);

        f = "FF1";
        comp.addFarmInternal(f);
        fix.detectChanges();

        node = checkTable(7, 5);
        expect(cell(node, 0, 3)).toBe(f);
        
        p = "PP1";
        comp.addPlantInternal(p);
        fix.detectChanges();

        node = checkTable(8, 5);
        expect(cell(node, 6, 0)).toBe(p);

        comp.addHarvestInternal(f, p, q);
        fix.detectChanges();

        node = checkTable(8, 5);
        expect(cell(node, 6, 3)).toBe(""+q);
        expect(cell(node, 1, 3)).toBe(""+q);
        expect(cell(node, 7, 3)).toBe(""+q);
        expect(cell(node, 6, 4)).toBe(""+q);
        expect(cell(node, 7, 4)).toBe(""+26);
        expect(cell(node, 1, 4)).toBe(""+26);
        
        fix.destroy();
      });
    });
  }));

});
开发者ID:Tattvum,项目名称:nallakeerai,代码行数:100,代码来源:bundles.component.spec.ts

示例4: describe

describe('DemoFormWithValidationsExplicit', () => {
  var el, input, form;

  beforeEachProviders(() => { return [FormBuilder]; });

  function createComponent(tcb: TestComponentBuilder): Promise<ComponentFixture> {
    return tcb.createAsync(DemoFormWithValidationsExplicit).then((fixture) => {
      el = fixture.debugElement.nativeElement;
      input = fixture.debugElement.query(By.css("input")).nativeElement;
      form = fixture.debugElement.query(By.css("form")).nativeElement;
      fixture.detectChanges();

      return fixture;
    });
  }

  it('displays errors with no sku', injectAsync([TestComponentBuilder], (tcb) => {
    return createComponent(tcb).then((fixture) => {
      input.value = '';
      dispatchEvent(input, 'input');
      fixture.detectChanges();

      let msgs = el.querySelectorAll('.ui.error.message');
      expect(msgs[0]).toHaveText('SKU is invalid');
      expect(msgs[1]).toHaveText('SKU is required');
    });
  }));

  it('displays no errors when sku has a value', injectAsync([TestComponentBuilder], (tcb) => {
    return createComponent(tcb).then((fixture) => {
      input.value = 'ABC';
      dispatchEvent(input, 'input');
      fixture.detectChanges();

      let msgs = el.querySelectorAll('.ui.error.message');
      expect(msgs.length).toEqual(0);
    });
  }));
});
开发者ID:Gitjerryzhong,项目名称:angular2,代码行数:39,代码来源:demo_form_with_validations_explicit.spec.ts

示例5: describe

import { describe, expect, it, beforeEachProviders, injectAsync, TestComponentBuilder } from 'angular2/testing';
import { AuthService } from 'src/core/auth';
import { ProjectService } from 'src/core/project';
import { Projects } from './projects';


describe('Projects', () => {
  beforeEachProviders(() => [
    AuthService,
    ProjectService
  ]);

  it('should display a list of projects', injectAsync([TestComponentBuilder], tcb => {
    return new Promise(resolve => {
      tcb.createAsync(Projects)
        .then(fixture => {
          fixture.detectChanges();
          let compiled = fixture.nativeElement;

          return fixture.componentInstance.loaded.then(() => {
            fixture.detectChanges();
            expect(compiled.querySelectorAll('li').length).toBe(2);
            resolve();
          });
        });
    });
  }));
});
开发者ID:ASK83,项目名称:angular2-webpack-seed,代码行数:28,代码来源:projects.spec.ts

示例6: main

export function main() {

  interface ITestFixture {
    fixture:ComponentFixture;
    component:MdSidenav;
    debug:DebugElement;
  }

  @Component({
    selector: 'test-app',
    directives: [MdSidenav],
    template: `
    <md-sidenav-container>
      <md-sidenav name="test"></md-sidenav>
    </md-sidenav-container>`
  })
  class TestComponent {
  }

  describe('Sidenav Service', () => {
    let builder: TestComponentBuilder;
    let service: SidenavService;

    function setup(template: string = null): Promise<ITestFixture> {
      let prep = template === null ?
        builder.createAsync(TestComponent) :
        builder.overrideTemplate(TestComponent, template).createAsync(TestComponent);
      return prep.then((fixture: ComponentFixture) => {
        fixture.detectChanges();
        let debug = fixture.debugElement.query(By.css('md-sidenav'));
        return {
          fixture: fixture,
          component: debug.componentInstance,
          debug: debug
        };
      }).catch(console.error.bind(console));
    }

    beforeEach(inject([TestComponentBuilder, SidenavService], (tcb, serv) => {
      builder = tcb;
      service = serv;
    }));

    describe('find', () => {
      it('should find sidenav by name', injectAsync([], () => {
        return setup().then((api: ITestFixture) => {
          expect(service.find('test')).not.toBeNull();
          expect(service.find('fake')).toBeNull();
          api.fixture.destroy();
        });
      }));
    });
    describe('show', () => {
      it('should show sidenav by name', injectAsync([], () => {
        return setup()
          .then(() => service.show('test'));
      }));
      it('should reject with invalid sidenav name', injectAsync([], () => {
        return setup()
          .then(() => service.show('fake'))
          .catch(() => Promise.resolve());
      }));
    });
    describe('hide', () => {
      it('should hide sidenav by name', injectAsync([], () => {
        return setup()
          .then(() => service.hide('test'));
      }));
      it('should reject with invalid sidenav name', injectAsync([], () => {
        return setup()
          .then(() => service.hide('fake'))
          .catch(() => Promise.resolve());
      }));
    });

  });
}
开发者ID:LiTiang,项目名称:ng2-material,代码行数:77,代码来源:sidenav_service_spec.ts

示例7: describe

import {
  it,
  iit,
  describe,
  ddescribe,
  expect,
  inject,
  injectAsync,
  TestComponentBuilder,
  beforeEachProviders
} from 'angular2/testing';
import {provide} from 'angular2/core';
import {TodoService} from './todo-service';


describe('TodoService Service', () => {

  beforeEachProviders(() => [TodoService]);


  it('should ...', inject([TodoService], (service:TodoService) => {

  }));

});
开发者ID:gotstago,项目名称:rxjs-learning,代码行数:25,代码来源:todo-service.spec.ts

示例8: describe

describe('artists.service', () => {

    beforeEachProviders(() => {
        return [
            HTTP_PROVIDERS,
            provide(XHRBackend, { useClass: MockBackend }),
            ArtistsService
        ];
    });


    beforeEach(() => {
        this.artists = [
            {
                artist_id: 1,
                name: "Muse",
                image_url: "muse.jpg",
                biography: "bio1"
            },
            {
                artist_id: 2,
                name: "Breaking Benjamin",
                image_url: "breaking_benjamin.jpg",
                biography: "bio2"
            },
        ];
    });

    it('retrieve all artists', inject([XHRBackend, ArtistsService], (mockBackend, artistsService: ArtistsService) => {
        mockBackend.connections.subscribe(
            (connection: MockConnection) => {
                connection.mockRespond(new Response(
                    new ResponseOptions({
                        body: this.artists
                    }
                    )));
            });

        artistsService.getArtists().subscribe(
            (artists: IArtist[]) => {
                expect(artists).toBeDefined();
                expect(artists.length).toEqual(2);
            }
        );
    }));

    it('retrieve one artist', inject([XHRBackend, ArtistsService], (mockBackend, artistsService: ArtistsService) => {
        mockBackend.connections.subscribe(
            (connection: MockConnection) => {
                connection.mockRespond(new Response(
                    new ResponseOptions({
                        body: this.artists
                    }
                    )));
            });

        artistsService.getArtist(2).subscribe(
            (artist: IArtist) => {
                expect(artist).toBeDefined();
                expect(artist.name).toBe("Breaking Benjamin");
            }
        );
    }));


});
开发者ID:smithga,项目名称:musicapp,代码行数:66,代码来源:artists.service.spec.ts

示例9: describe

import {
  it,
  inject,
  injectAsync,
  describe,
  beforeEachProviders,
  TestComponentBuilder
} from 'angular2/testing';

import {Component, provide} from 'angular2/core';

// Load the implementations that should be tested
import {Login} from './login.component';

describe('Login', () => {
  // provide our implementations or mocks to the dependency injector
  beforeEachProviders(() => [
    Login
  ]);

  it('should log ngOnInit', inject([ Login ], (login) => {
    spyOn(console, 'log');
    expect(console.log).not.toHaveBeenCalled();

    login.ngOnInit();
    expect(console.log).toHaveBeenCalled();
  }));

});
开发者ID:silvercrow,项目名称:pepscards,代码行数:29,代码来源:login.spec.ts

示例10: main

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

    var fixture: ComponentFixture;
    var analytics: any;

    beforeEachProviders(() => [
      TEST_ROUTER_PROVIDERS,
      Angulartics2,
      Angulartics2Segment
    ]);

    beforeEach(function() {
      window.analytics = analytics = {
        page: jasmine.createSpy('page'),
        track: jasmine.createSpy('track'),
        identify: jasmine.createSpy('identify'),
        alias: jasmine.createSpy('alias')
      }
    });

    it('should track initial page',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2Segment],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2Segment: Angulartics2Segment) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/', component: HelloCmp })]))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(analytics.page).toHaveBeenCalledWith('');
                  resolve();
                });
              });
            });
        }));

    it('should track pages',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2Segment],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2Segment: Angulartics2Segment) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/abc', component: HelloCmp })]))
            .then((_) => router.navigateByUrl('/abc'))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(analytics.page).toHaveBeenCalledWith('/abc');
                  resolve();
                });
              });
            });
        }));

    it('should track events',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Segment],
        (tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Segment: Angulartics2Segment) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.eventTrack.next({ action: 'do', properties: { category: 'cat' } }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                // setTimeout(() => {
                  expect(analytics.track).toHaveBeenCalledWith('do', { category: 'cat' });
                  resolve();
                // });
              });
            });
        }));

    it('should set user properties',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Segment],
        ((tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Segment: Angulartics2Segment) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.setUserProperties.next({ userId: '1', firstName: 'John', lastName: 'Doe' }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(analytics.identify).toHaveBeenCalledWith('1', { userId: '1', firstName: 'John', lastName: 'Doe' });
                  resolve();
                });
              });
            });
        })));

    it('should set user properties once',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Segment],
        ((tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Segment: Angulartics2Segment) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.setUserPropertiesOnce.next({ userId: '1', firstName: 'John', lastName: 'Doe' }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
//.........这里部分代码省略.........
开发者ID:jamescarter-le,项目名称:angulartics2,代码行数:101,代码来源:angulartics2-segment.spec.ts


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