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


TypeScript testing.TestRequest类代码示例

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


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

示例1: describe

describe('IscsiTargetDiscoveryModalComponent', () => {
  let component: IscsiTargetDiscoveryModalComponent;
  let fixture: ComponentFixture<IscsiTargetDiscoveryModalComponent>;
  let httpTesting: HttpTestingController;
  let req: TestRequest;

  const elem = (css) => fixture.debugElement.query(By.css(css));
  const elemDisabled = (css) => elem(css).nativeElement.disabled;

  configureTestBed({
    declarations: [IscsiTargetDiscoveryModalComponent],
    imports: [
      HttpClientTestingModule,
      ReactiveFormsModule,
      SharedModule,
      ToastModule.forRoot(),
      RouterTestingModule
    ],
    providers: [i18nProviders, BsModalRef]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(IscsiTargetDiscoveryModalComponent);
    component = fixture.componentInstance;
    httpTesting = TestBed.get(HttpTestingController);
  });

  describe('with update permissions', () => {
    beforeEach(() => {
      component.permission = new Permission(['update']);
      fixture.detectChanges();
      req = httpTesting.expectOne('api/iscsi/discoveryauth');
    });

    it('should create', () => {
      expect(component).toBeTruthy();
    });

    it('should create form', () => {
      expect(component.discoveryForm.value).toEqual({
        user: '',
        password: '',
        mutual_user: '',
        mutual_password: ''
      });
    });

    it('should patch form', () => {
      req.flush({
        user: 'foo',
        password: 'bar',
        mutual_user: 'mutual_foo',
        mutual_password: 'mutual_bar'
      });
      expect(component.discoveryForm.value).toEqual({
        user: 'foo',
        password: 'bar',
        mutual_user: 'mutual_foo',
        mutual_password: 'mutual_bar'
      });
    });

    it('should submit new values', () => {
      component.discoveryForm.patchValue({
        user: 'new_user',
        password: 'new_pass',
        mutual_user: 'mutual_new_user',
        mutual_password: 'mutual_new_pass'
      });
      component.submitAction();

      const submit_req = httpTesting.expectOne('api/iscsi/discoveryauth');
      expect(submit_req.request.method).toBe('PUT');
      expect(submit_req.request.body).toEqual({
        user: 'new_user',
        password: 'new_pass',
        mutual_user: 'mutual_new_user',
        mutual_password: 'mutual_new_pass'
      });
    });

    it('should enable form if user has update permission', () => {
      expect(elemDisabled('input#user')).toBeFalsy();
      expect(elemDisabled('input#password')).toBeFalsy();
      expect(elemDisabled('input#mutual_user')).toBeFalsy();
      expect(elemDisabled('input#mutual_password')).toBeFalsy();
      expect(elem('cd-submit-button')).toBeDefined();
    });
  });

  it('should disabled form if user does not have update permission', () => {
    component.permission = new Permission(['read', 'create', 'delete']);
    fixture.detectChanges();
    req = httpTesting.expectOne('api/iscsi/discoveryauth');

    expect(elemDisabled('input#user')).toBeTruthy();
    expect(elemDisabled('input#password')).toBeTruthy();
    expect(elemDisabled('input#mutual_user')).toBeTruthy();
    expect(elemDisabled('input#mutual_password')).toBeTruthy();
    expect(elem('cd-submit-button')).toBeNull();
//.........这里部分代码省略.........
开发者ID:LenzGr,项目名称:ceph,代码行数:101,代码来源:iscsi-target-discovery-modal.component.spec.ts

示例2: describe

describe('IscsiTargetDiscoveryModalComponent', () => {
  let component: IscsiTargetDiscoveryModalComponent;
  let fixture: ComponentFixture<IscsiTargetDiscoveryModalComponent>;
  let httpTesting: HttpTestingController;
  let req: TestRequest;

  configureTestBed({
    declarations: [IscsiTargetDiscoveryModalComponent],
    imports: [HttpClientTestingModule, ReactiveFormsModule, SharedModule, ToastModule.forRoot()],
    providers: [i18nProviders, BsModalRef]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(IscsiTargetDiscoveryModalComponent);
    component = fixture.componentInstance;
    httpTesting = TestBed.get(HttpTestingController);
    fixture.detectChanges();
    req = httpTesting.expectOne('api/iscsi/discoveryauth');
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should create form', () => {
    expect(component.discoveryForm.value).toEqual({
      user: '',
      password: '',
      mutual_user: '',
      mutual_password: ''
    });
  });

  it('should patch form', () => {
    req.flush({
      user: 'foo',
      password: 'bar',
      mutual_user: 'mutual_foo',
      mutual_password: 'mutual_bar'
    });
    expect(component.discoveryForm.value).toEqual({
      user: 'foo',
      password: 'bar',
      mutual_user: 'mutual_foo',
      mutual_password: 'mutual_bar'
    });
  });

  it('should submit new values', () => {
    component.discoveryForm.patchValue({
      user: 'new_user',
      password: 'new_pass',
      mutual_user: 'mutual_new_user',
      mutual_password: 'mutual_new_pass'
    });
    component.submitAction();

    const submit_req = httpTesting.expectOne('api/iscsi/discoveryauth');
    expect(submit_req.request.method).toBe('PUT');
    expect(submit_req.request.body).toEqual({
      user: 'new_user',
      password: 'new_pass',
      mutual_user: 'mutual_new_user',
      mutual_password: 'mutual_new_pass'
    });
  });
});
开发者ID:YankunLi,项目名称:ceph,代码行数:67,代码来源:iscsi-target-discovery-modal.component.spec.ts

示例3: describe

describe('HttpMainMiddleware', () => {
	let httpClient: HttpClient
	let httpTestingController: HttpTestingController
	let httpMiddleware: HttpMainMiddleware
	let req: TestRequest
	let nsSpyObj: jasmine.SpyObj<NotificationsService>
	const testData: { name: string } = { name: 'Test' }, path = '/test'
	beforeEach(() => {
		nsSpyObj = jasmine.createSpyObj<NotificationsService>('NotificationsService', ['notify'])
		httpMiddleware = new HttpMainMiddleware(nsSpyObj)
		TestBed.configureTestingModule({
			imports: [
				HttpClientTestingModule,
			], providers : [
				{ provide: HTTP_INTERCEPTORS, useValue: httpMiddleware, multi: true }
			]
		})

		httpClient = TestBed.get(HttpClient)
		httpTestingController = TestBed.get(HttpTestingController)

		spyOn<HttpMainMiddleware>(httpMiddleware, 'intercept').and.callThrough()
		spyOn<HttpMainMiddleware>(httpMiddleware, 'logRequest').and.callThrough()
	})

	afterEach(() => {
		httpTestingController.verify()
	})

	describe('a request that is NOT svg', () => {
		beforeEach(() => {
			httpClient.get<{ name: string }>(path).subscribe()
			req = httpTestingController.expectOne(path)
			req.flush(testData)
		})

		it('should call the intercept method', () => {
			expect(httpMiddleware.intercept).toHaveBeenCalled()
		})

		it('should call the logRequest method', () => {
			expect(httpMiddleware.logRequest).toHaveBeenCalled()
		})

		it(format('should call the logRequest method with {0},{1}', 'GET', path), () => {
			expect(httpMiddleware.logRequest).toHaveBeenCalledWith(path, 'GET')
		})

		it('should call the ns notify method with info type', () => {
			expect(nsSpyObj.notify.calls.argsFor(0)).toEqual(jasmine.arrayContaining(['info']))
		})
	})

	describe('a request that is svg', () => {
		beforeEach(() => {
			httpClient.get<{ name: string }>('/assets/img.svg').subscribe()
			req = httpTestingController.expectOne('/assets/img.svg')
			req.flush(testData)
		})

		it('should NOT call the ns notify method', () => {
			expect(nsSpyObj.notify).not.toHaveBeenCalled()
		})
	})
})
开发者ID:marsojane,项目名称:sasutil,代码行数:65,代码来源:http-main-middleware.spec.ts

示例4: it

 it('should patch form', () => {
   req.flush({
     user: 'foo',
     password: 'bar',
     mutual_user: 'mutual_foo',
     mutual_password: 'mutual_bar'
   });
   expect(component.discoveryForm.value).toEqual({
     user: 'foo',
     password: 'bar',
     mutual_user: 'mutual_foo',
     mutual_password: 'mutual_bar'
   });
 });
开发者ID:LenzGr,项目名称:ceph,代码行数:14,代码来源:iscsi-target-discovery-modal.component.spec.ts

示例5:

		beforeEach(() => {
			httpClient.get<{ name: string }>('/assets/img.svg').subscribe()
			req = httpTestingController.expectOne('/assets/img.svg')
			req.flush(testData)
		})
开发者ID:marsojane,项目名称:sasutil,代码行数:5,代码来源:http-main-middleware.spec.ts


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