本文整理汇总了TypeScript中Sinon.fakeServer.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript fakeServer.create方法的具体用法?TypeScript fakeServer.create怎么用?TypeScript fakeServer.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sinon.fakeServer
的用法示例。
在下文中一共展示了fakeServer.create方法的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()
})
示例2: beforeEach
beforeEach((): void => {
fakeServer = sinon.fakeServer.create({respondImmediately: true});
registrationController["device"] = device;
deviceName = $("<input>")
.attr("id", "deviceName")
.val("new-device")
.appendTo(document.body);
});
示例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;
});
示例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'
})
})
示例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);
}
});
}
示例6: beforeEach
beforeEach(() => {
server = fakeServer.create();
server.respondImmediately = true;
transport = new Transports.XHRTransport({ dsn: testDsn });
});
示例7: beforeEach
beforeEach(() => {
server.restore();
server = fakeServer.create();
});
示例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',
});
//.........这里部分代码省略.........
示例9: Loader
test.beforeEach(t => {
t.context.loader = new Loader();
server = sinon.fakeServer.create();
});