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


TypeScript TestBed.initTestEnvironment方法代码示例

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


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

示例1: platformBrowserDynamicTesting

const testModuleConfig = () => {
  TestBed.resetTestEnvironment();

  TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting())
    .configureTestingModule({
      imports: [
        RouterTestingModule,
        StoreModule.forFeature('i18n', reducers),
        EffectsModule.forFeature([LanguageEffects]),
        CoreModule.forRoot([
          {
            provide: ConfigLoader,
            useFactory: configFactory,
            deps: [
              PLATFORM_ID,
              HttpClient
            ]
          }
        ]),
        CoreTestingModule,
        NgrxTestingModule,
        AnalyticsModule,
        I18NTestingModule
      ],
      providers: [
        LanguageEffects
      ]
    });
};
开发者ID:John123Yu,项目名称:universal-1,代码行数:29,代码来源:language.effects.spec.ts

示例2: describe

describe('FeedsListComponent', () => {
  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [MockRoutes],
      declarations: [FeedsListComponent, FeedsComponent, EllipsisAfterPipe, RouterTestingComponent],
      providers: [
        { provide: FeedsService, useClass: MockFeedsService }
      ]
    });
  });

  it('can fetch the feeds list', async(() => {
    return TestBed
      .compileComponents().then(() => {
        let componentFixture = TestBed.createComponent(FeedsListComponent);
        let element = componentFixture.nativeElement;
        componentFixture.detectChanges();
        expect(componentFixture.componentInstance.feeds.length).toBe(1);
        expect(componentFixture.componentInstance.feeds[0].title).toBe('Post 1');
      });
  }));
});
开发者ID:ramana-chavakula,项目名称:angular2-webpack,代码行数:27,代码来源:feedsList.component.spec.ts

示例3: describe

describe('EllipsisAfterPipe', () => {
  let ellipsisAfterPipe: EllipsisAfterPipe;

  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [EllipsisAfterPipe]
    });
  });

  beforeEach(() => {
    ellipsisAfterPipe = new EllipsisAfterPipe();
  });

  it('should create the EllipsisAfterPipe', () => {
    expect(ellipsisAfterPipe).toBeTruthy();
  });

  it('can obtain same string incase its length is less than the limit', () => {
    expect(ellipsisAfterPipe.transform('abc', 10)).toEqual('abc');
  });

  it('can add ellipsis after the specified limit', () => {
    expect(ellipsisAfterPipe.transform('abcdefghijklmnopqrstuvwxyz', 10)).toEqual('abcdefghij ...');
  });
});
开发者ID:ramana-chavakula,项目名称:angular2-webpack,代码行数:30,代码来源:feeds.pipe.spec.ts

示例4: platformBrowserDynamicTesting

export function setup<T>(moduleType: Type<T>, options: { storedValue?: any } = {}) {
  TestBed.resetTestEnvironment();
  TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
  const bootstrap: BootstrapModuleFn<T> = () =>
    getTestBed().platform.bootstrapModule(moduleType);
  const storedValue = options.storedValue;
  const storageValue = options.storedValue ? JSON.stringify(storedValue) : '';
  sessionStorage.setItem(NGXS_HMR_SNAPSHOT_KEY, storageValue);
  MockState.clear();
  return { bootstrap };
}
开发者ID:LucasFrecia,项目名称:store,代码行数:11,代码来源:hmr-helpers.ts

示例5: analyzeAppProvidersForDeprecatedConfiguration

    [(appProviders: any[]) => {
      const deprecatedConfiguration = analyzeAppProvidersForDeprecatedConfiguration(appProviders);
      const platformRef = createPlatformFactory(platformServerTesting, 'serverTestingDeprecated', [{
                                                  provide: COMPILER_OPTIONS,
                                                  useValue: deprecatedConfiguration.compilerOptions,
                                                  multi: true
                                                }])();

      @NgModule({
        exports: [ServerTestingModule],
        declarations: [deprecatedConfiguration.moduleDeclarations]
      })
      class DynamicTestModule {
      }

      const testInjector = TestBed.initTestEnvironment(DynamicTestModule, platformRef);
      const console: Console = testInjector.get(Console);
      deprecatedConfiguration.deprecationMessages.forEach((msg) => console.warn(msg));
    }];
开发者ID:Jake-Church,项目名称:angular,代码行数:19,代码来源:server.ts

示例6: platformBrowserDynamicTesting

const testModuleConfig = () => {
  TestBed.resetTestEnvironment();

  TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting())
    .configureTestingModule({
      imports: [
        CoreModule.forRoot([
          {
            provide: ConfigLoader,
            useFactory: configFactory,
            deps: [
              PLATFORM_ID,
              HttpClient
            ]
          }
        ]),
        CoreTestingModule
      ]
    });
};
开发者ID:John123Yu,项目名称:universal-1,代码行数:20,代码来源:language.reducer.spec.ts

示例7: task

task('test:ssr', [':test:build'], (done: () => void) => {
  const baseUrl = join(projectDir, 'dist', 'packages', 'flex-layout');
  const paths = {
    '@angular/flex-layout/*': ['./*']
  };
  register({baseUrl, paths});
  const jasmine = new (require('jasmine'))({projectBaseDir: projectDir});
  require('zone.js');
  require('zone.js/dist/zone-testing');
  const {TestBed} = require('@angular/core/testing');
  const {ServerTestingModule, platformServerTesting} = require('@angular/platform-server/testing');
  let testBed = TestBed.initTestEnvironment(
    ServerTestingModule,
    platformServerTesting()
  );

  patchTestBed(testBed);
  jasmine.loadConfigFile('test/jasmine-ssr.json');
  jasmine.execute();
  done();
});
开发者ID:marffox,项目名称:flex-layout,代码行数:21,代码来源:unit-test-ssr.ts

示例8: describe

describe('ContactComponent', () => {
  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [ContactComponent]
    });
  });

  it('should create the component and display a message', async(() => {
    return TestBed
      .compileComponents().then(() => {
        let componentFixture = TestBed.createComponent(ContactComponent);
        let element = componentFixture.nativeElement;
        let componentInstance = componentFixture.componentInstance;
        componentFixture.detectChanges();
        expect(element).toBeTruthy();
        expect(componentInstance.message).toEqual('Contact me on chnvrm@gmail.com');
      });
  }));
});
开发者ID:ramana-chavakula,项目名称:angular2-webpack,代码行数:24,代码来源:contact.component.spec.ts

示例9: describe

describe('FeedsService', () => {
  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        BaseRequestOptions,
        MockBackend,
        FeedsService,
        {
          provide: Http, useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
            return new Http(backend, defaultOptions);
          }, deps: [MockBackend, BaseRequestOptions]
        },
      ]
    });
  });

  it('can retrive feeds', inject([FeedsService, MockBackend],
    fakeAsync((feedsService: FeedsService, mockBackend: MockBackend) => {
      let result: IFeed[];
      mockBackend.connections.subscribe((connection: any) => {
        expect(connection.request.url).toBe('./data/feeds.json');
        let response = new ResponseOptions({
          body: [{
            'id': 'fid1',
            'title': 'Post 1',
            'description': 'Post Description 1'
          }]
        });
        connection.mockRespond(new Response(response));
      });
      feedsService.getFeeds().subscribe((response) => {
        result = response;
      });
      tick();
      expect(result[0].id).toBe('fid1');
      expect(result[0].title).toBe('Post 1');
      expect(result[0].description).toBe('Post Description 1');
    })
  ));

  it('can retrive the feed using feed id', inject([FeedsService, MockBackend],
    fakeAsync((feedsService: FeedsService, mockBackend: MockBackend) => {
      let result: IFeed;
      mockBackend.connections.subscribe((connection: any) => {
        expect(connection.request.url).toBe('./data/feeds.json');
        let response = new ResponseOptions({
          body: [{
            'id': 'fid1',
            'title': 'Post 1',
            'description': 'Post Description 1'
          }, {
            'id': 'fid2',
            'title': 'Post 2',
            'description': 'Post Description 2'
          }]
        });
        connection.mockRespond(new Response(response));
      });
      feedsService.getFeed('fid2').subscribe((response) => {
        result = response;
      });
      tick();
      expect(result.id).toBe('fid2');
      expect(result.title).toBe('Post 2');
      expect(result.description).toBe('Post Description 2');
    })
  ));
});
开发者ID:ramana-chavakula,项目名称:angular2-webpack,代码行数:73,代码来源:feeds.service.spec.ts

示例10: require

 * This software is released under MIT license.
 * The full license information can be found in LICENSE in the root directory of this project.
 */

import "core-js";
import "core-js/es7/reflect";
import "zone.js/dist/zone";
import "zone.js/dist/long-stack-trace-zone";
import "zone.js/dist/async-test";
import "zone.js/dist/fake-async-test";
import "zone.js/dist/sync-test";
import "zone.js/dist/proxy";
import "zone.js/dist/jasmine-patch";
import JasmineExpect from "jasmine-expect";

/* tslint:disable no-var-requires no-require-imports */
const browserTesting = require("@angular/platform-browser-dynamic/testing");
const coreTesting = require("@angular/core/testing");
// include every .spec.ts file inside src, except for those in ks-app folder
const context = (require as any).context("../src/", true, /^((?![\\/]ks-app[\\/]).)*\.spec\.ts$/);
/* tslint:enable no-var-requires no-require-imports*/

Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;

coreTesting.TestBed.resetTestEnvironment();
coreTesting.TestBed.initTestEnvironment(browserTesting.BrowserDynamicTestingModule,
                                        browserTesting.platformBrowserDynamicTesting());

context.keys().forEach(context);
开发者ID:beqom,项目名称:clarity,代码行数:30,代码来源:tests.entry.ts


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