當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。