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


TypeScript testing.afterEach函数代码示例

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


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

示例1: describe

describe('Service: LocalStorage', () => {
  beforeEach(() => {
    addProviders([LocalStorageService]);
    window.localStorage.clear();
  });

  afterEach(() => {
    window.localStorage.clear();
  });

  it('exists',
    inject([LocalStorageService],
      (service: LocalStorageService) => {
        expect(service).toBeTruthy();
      }));

  it('stores items in localStorage',
    inject([LocalStorageService],
      (service: LocalStorageService) => {
        let item = { key: 'value' };
        service.setItem(mockStorageKey, item);

        expect(window.localStorage.getItem(mockStorageKey)).toEqual(item);
      }));

  it('gets items from localStorage',
    inject([LocalStorageService],
      (service: LocalStorageService) => {
        let item = { key: 'value' };
        window.localStorage.setItem(mockStorageKey, JSON.stringify(item));

        expect(service.getItem(mockStorageKey)).toEqual(item);
      }));
});
开发者ID:mzolkiewski,项目名称:ng2-cli-todos,代码行数:34,代码来源:local-storage.service.spec.ts

示例2: describe

  describe('platform-server integration', () => {

    afterEach(() => disposePlatform());

    it('should bootstrap', async(() => {
         var body = writeBody('<app></app>');
         serverBootstrap(MyServerApp).then(() => {
           expect(getDOM().getText(body)).toEqual('Works!');
         });
       }));
  });
开发者ID:alexbecker,项目名称:angular,代码行数:11,代码来源:integration_spec.ts

示例3: describe

  describe('platform-server integration', () => {

    beforeEach(() => disposePlatform());
    afterEach(() => disposePlatform());

    it('should bootstrap', async(() => {
         var body = writeBody('<app></app>');
         serverBootstrap(MyServerApp, [
           BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS
         ]).then(() => { expect(getDOM().getText(body)).toEqual('Works!'); });
       }));
  });
开发者ID:AudreyChao,项目名称:angular,代码行数:12,代码来源:integration_spec.ts

示例4: describe

  describe('title service', () => {
    var initialTitle = getDOM().getTitle();
    var titleService = new Title();

    afterEach(() => { getDOM().setTitle(initialTitle); });

    it('should allow reading initial title',
       () => { expect(titleService.getTitle()).toEqual(initialTitle); });

    it('should set a title on the injected document', () => {
      titleService.setTitle('test title');
      expect(getDOM().getTitle()).toEqual('test title');
      expect(titleService.getTitle()).toEqual('test title');
    });

    it('should reset title to empty string if title not provided', () => {
      titleService.setTitle(null);
      expect(getDOM().getTitle()).toEqual('');
    });

  });
开发者ID:0xJoKe,项目名称:angular,代码行数:21,代码来源:title_spec.ts

示例5: describe

    describe('With DefaultDriverType', function() {
      const TEST_KEY = `${CUSTOM_NAMESPACE}-${Math.random() * 1000}`

      beforeEachProviders(() => [provide(LockerConfig, {useValue: new LockerConfig(null, driver)}), Locker])
      afterEach(() => driver.clear())

      it(`sets driver to ${driverName}`, inject([Locker, LockerConfig], function(locker: Locker) {
        expect(locker['driver']).toEqual(driver)
      }))


      it('sets key with string value into storage', inject([Locker], function(locker: Locker) {
        const TEST_VALUE = 'TEST'

        locker.set(TEST_KEY, TEST_VALUE)

        expect(locker.get(TEST_KEY)).toEqual(TEST_VALUE)
      }))

      it('sets key with object value into storage', inject([Locker], function(locker: Locker) {
        const TEST_VALUE = {
          object1: 'villa',
          myObject: 'Test'
        }

        locker.set(TEST_KEY, TEST_VALUE)

        expect(locker.get(TEST_KEY)).toEqual(TEST_VALUE)
      }))

      it('removes data from storage with .remove', inject([Locker], function(locker: Locker) {
        const TEST_VALUE = 'TEST'

        locker.set(TEST_KEY, TEST_VALUE)

        locker.remove(TEST_KEY)
        expect(locker.get(TEST_KEY)).not.toEqual(TEST_VALUE)
      }))

      it('clears all data from the storage with .clear', inject([Locker], function(locker: Locker) {
        const TEST_VALUE = 'TEST',
              TEST_KEY_2 = `TEST_${TEST_KEY}`

        locker.set(TEST_KEY, TEST_VALUE)
        locker.set(TEST_KEY_2, TEST_VALUE)

        locker.clear()

        expect(locker.get(TEST_KEY)).not.toEqual(TEST_VALUE)
        expect(locker.get(TEST_KEY_2)).not.toEqual(TEST_VALUE)
      }))

      it('can fetch key by index', inject([Locker], function(locker: Locker) {
        var dummy = {
          key: 'TEST',
          data: `TEST-${Math.random() * 1000}`
        }

        locker.set(dummy.key, dummy.data)

        expect(locker.key()).toEqual(dummy.key)
      }))
    })
开发者ID:robscotts4rb,项目名称:angular2-locker,代码行数:63,代码来源:TestDriver.ts

示例6: describe

describe('Page1Service standalone TEST ' + '-'.repeat(40), () => {
  let service: Page1Service;
  let clock: lolex.Clock;

  beforeEachProviders(() => [
    Page1Service,
  ]);


  beforeEach(inject([Page1Service], (_service) => {
    service = _service;
  }));


  afterEach(() => {
    try {
      clock.uninstall();
    } catch (e) { }
  });


  it('can create', asyncPower(async () => {
    assert(!!service);
  }));


  // このテストはfakeAsyncテストでは通らない。asyncテストでもsetTimeoutしないと通らない。
  // ServiceからsetInterval(Observable.timer)を取り除けばこんなややこしいことをしなくてもテストが通る。
  it('counter value must be increment correctly', asyncPower(async () => {
    await setTimeoutPromise(0, true); // setTimeoutしてzoneのfirst turnから抜けた状態じゃないと下記のテストは通らない。    
    assert(observableValue(service.counter$) === 0);
    service.increment(1);
    assert(observableValue(service.counter$) === 1);
    service.increment(1);
    assert(observableValue(service.counter$) === 2);
    service.increment(2);
    assert(observableValue(service.counter$) === 4);
  }));


  // らこさんエディション
  it('counter value must be increment correctly by @laco', async(() => {
    let value: number;
    service.counter$.subscribe(counter => value = counter);

    setTimeout(() => {
      service.increment(1);
      assert(value === 1);
      service.increment(1);
      assert(value === 2);
      service.increment(2);
      assert(value === 4);
    }, 0);
  }));

  it('exprimental 2', asyncPower(async () => {
    await setTimeoutPromise(0, true);
    let counter: number;
    let currentTime: number;
    let previousTime: number;
    service.counter$.subscribe(value => counter = value);
    service.timeNow$.subscribe(value => {
      if (currentTime) {
        previousTime = currentTime;
      }
      currentTime = value;
    });

    service.increment(1);
    assert(counter === 1);
    service.increment(1);
    assert(counter === 2);
    service.increment(2);
    assert(counter === 4);

    await setTimeoutPromise(1000);
    console.log([previousTime, currentTime]);
    assert(previousTime + 1000 <= currentTime);
  }));

});
开发者ID:ovrmrw,项目名称:angular2-testing-sample,代码行数:81,代码来源:page1.service.spec.ts


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