當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Sinon.fakeServer類代碼示例

本文整理匯總了TypeScript中Sinon.fakeServer的典型用法代碼示例。如果您正苦於以下問題:TypeScript fakeServer類的具體用法?TypeScript fakeServer怎麽用?TypeScript fakeServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了fakeServer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

 beforeEach(() => {
   server = sinon.fakeServer.create()
   server.autoRespond = true
   server.respondWith('GET', 'https://example.com/views/hello.html',
     [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']);
   (global as any).XMLHttpRequest = sinon.useFakeXMLHttpRequest()
 })
開發者ID:harttle,項目名稱:shopify-liquid,代碼行數:7,代碼來源:browser.ts

示例2: beforeEach

		beforeEach((): void => {
			fakeServer = sinon.fakeServer.create({respondImmediately: true});
			registrationController["device"] = device;
			deviceName = $("<input>")
				.attr("id", "deviceName")
				.val("new-device")
				.appendTo(document.body);
		});
開發者ID:scottohara,項目名稱:tvmanager,代碼行數:8,代碼來源:registration-controller_spec.ts

示例3: beforeEach

 beforeEach(() => {
   server = fakeServer.create();
   server.respondWith(
     'GET',
     OWM_API_STATION(),
     fakeResponse(200, MockStations)
   );
   server.respondWith(
     'GET',
     OWM_API_FORECAST(lat, lon),
     fakeResponse(200, MockForecasts)
   );
   server.respondImmediately = true;
 });
開發者ID:atSistemas,項目名稱:angular-base,代碼行數:14,代碼來源:weather-map.service.spec.ts

示例4: beforeEach

 beforeEach(() => {
   server = sinon.fakeServer.create()
   server.autoRespond = true
   server.respondWith('GET', 'https://example.com/views/hello.html',
     [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
   let dom = new JSDOM('', {
     url: 'https://example.com/foo/bar.html',
     contentType: 'text/html',
     includeNodeLocations: true
   });
   (global as any).XMLHttpRequest = sinon.FakeXMLHttpRequest;
   (global as any).document = dom.window.document
   engine = new Liquid({
     root: 'https://example.com/views/',
     extname: '.html'
   })
 })
開發者ID:harttle,項目名稱:shopify-liquid,代碼行數:17,代碼來源:xhr.ts

示例5: init

  private init() {
    let server = sinon.fakeServer.create({
      autoRespond: true,
      autoRespondAfterFn: this.autoRespondAfterFn.bind(this)
    });

    sinon.FakeXMLHttpRequest.useFilters = true;
    sinon.FakeXMLHttpRequest.addFilter(function (method, url) {
      let state = Leonardo.fetchStatesByUrlAndMethod(url, method);
      return !(state && state.active);
    });

    sinon.FakeXMLHttpRequest.onResponseEnd = function (xhr) {
      let res = xhr.response;
      try {
        res = JSON.parse(xhr.response);
      }
      catch (e) {
      }
      Leonardo._logRequest(xhr.method,
          xhr.url, xhr.status, xhr.requestHeaders,
          xhr.requestBody, xhr.getAllResponseHeaders(), res);
    };

    server.respondWith(function (request) {
      let state = Leonardo.fetchStatesByUrlAndMethod(request.url, request.method),
        activeOption = Leonardo.getActiveStateOption(state.name);

      if (!!activeOption) {
        const resStatus = activeOption.status;
        const resData = Utils.isFunction(activeOption.data) ? activeOption.data(request) : activeOption.data;
        let resHeaders = {'Content-Type': 'application/json'};
        if (activeOption.headers) {
          resHeaders = Utils.isFunction(activeOption.headers) ? activeOption.headers(request) : activeOption.headers;
        }

        request.respond(resStatus, resHeaders, JSON.stringify(resData));
        Leonardo._logRequest(request.method, request.url,
            resStatus, request.requestHeaders,
            request.requestBody, resHeaders, resData);
      } else {
        console.warn('could not find a state for the following request', request);
      }
    });
  }
開發者ID:,項目名稱:,代碼行數:45,代碼來源:

示例6: beforeEach

 beforeEach(() => {
   server = fakeServer.create();
   server.respondImmediately = true;
   transport = new Transports.XHRTransport({ dsn: testDsn });
 });
開發者ID:getsentry,項目名稱:raven-js,代碼行數:5,代碼來源:xhr.test.ts

示例7: beforeEach

	beforeEach(() => {
		server.restore();
		server = fakeServer.create();
	});
開發者ID:sutarmin,項目名稱:dx-platform,代碼行數:4,代碼來源:api-client.utils.test.ts

示例8: describe

describe('API Client', () => {
	let server = fakeServer.create();

	beforeEach(() => {
		server.restore();
		server = fakeServer.create();
	});

	afterEach(() => {
		server.restore();
	});

	describe('static #create', () => {
		it('should create instance with baseHref and extraHeaders', () => {
			const client = ApiClient.create('context', { 'X-FOO': 'test' });

			const sub$ = client
				.request({
					method: 'GET',
					url: '',
				})
				.subscribe();

			const request = server.requests[0];
			expect(request.url).toBe('context');
			expect(request.requestHeaders['X-FOO']).toBe('test');

			sub$.unsubscribe();
		});
	});

	describe('#request', () => {
		it('should return stream of remote data', () => {
			const client = ApiClient.create('/');

			const items1: any[] = [];
			const items2: any[] = [];

			client.request({ method: 'GET', url: '' }).subscribe(item => items1.push(item));
			client.request({ method: 'GET', url: '' }).subscribe(item => items2.push(item));

			expect(items1[0]).toEqual(pending);
			expect(items2[0]).toEqual(pending);

			const [req1, req2] = server.requests;

			req1.respond(200, {}, JSON.stringify({}));
			req2.respond(404, {}, '');

			expect(isSuccess(items1[1])).toBeTruthy();
			expect(isFailure(items2[1])).toBeTruthy();
		});
	});

	describe('shorthands: get, post, put, remove', () => {
		it('should use $request method with predefined parameters', () => {
			const client = ApiClient.create('/');
			const spy = jest.spyOn(client, 'request');

			client.get('test', { foo: 'bar' });

			expect(spy).toHaveBeenCalledWith({
				method: 'GET',
				url: 'test?foo=bar',
			});

			spy.mockReset();

			client.post('test', {
				foo: 'bar',
			});

			expect(spy).toHaveBeenCalledWith({
				method: 'POST',
				url: 'test',
				body: {
					foo: 'bar',
				},
			});

			spy.mockReset();

			client.put('test', {
				foo: 'bar',
			});

			expect(spy).toHaveBeenCalledWith({
				method: 'PUT',
				url: 'test',
				body: {
					foo: 'bar',
				},
			});

			spy.mockReset();

			client.remove('test', {
				foo: 'bar',
			});

//.........這裏部分代碼省略.........
開發者ID:sutarmin,項目名稱:dx-platform,代碼行數:101,代碼來源:api-client.utils.test.ts

示例9: Loader

test.beforeEach(t => {
    t.context.loader = new Loader();
    server = sinon.fakeServer.create();
});
開發者ID:bullhorn,項目名稱:chomsky,代碼行數:4,代碼來源:loader.spec.ts


注:本文中的Sinon.fakeServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。