当前位置: 首页>>代码示例>>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;未经允许,请勿转载。