Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4cfc5fa

Browse files
committedSep 27, 2016
use fake XMLHttpRequests
1 parent b3419f1 commit 4cfc5fa

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed
 

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"rewire": "^2.5.2",
5050
"rimraf": "2.5.3",
5151
"run-sequence": "^1.2.2",
52+
"sinon": "^1.17.6",
5253
"source-map-support": "0.4.2",
5354
"systemjs": "^0.19.39",
5455
"tracekit": "0.4.3",

‎src/ExceptionlessClient-spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { ExceptionlessClient } from './ExceptionlessClient';
22
import { EventPluginContext } from './plugins/EventPluginContext';
33
import { expect } from 'chai';
4+
import * as sinon from 'sinon';
45

56
describe('ExceptionlessClient', () => {
7+
let xhr: any;
8+
9+
beforeEach(() => {
10+
xhr = sinon.useFakeXMLHttpRequest();
11+
});
12+
13+
afterEach(() => {
14+
xhr.restore();
15+
});
16+
617
it('should use event reference ids', (done) => {
718
let error = new Error('From Unit Test');
819

‎src/queue/DefaultEventQueue-spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import { Configuration } from '../configuration/Configuration';
2+
import { SubmissionResponse } from '../submission/SubmissionResponse';
23
import { IEvent } from '../models/IEvent';
34
import { expect } from 'chai';
5+
import * as sinon from 'sinon';
46

57
describe('DefaultEventQueue', () => {
68

79
let config: Configuration;
10+
let xhr: any;
11+
let requests: Array<any>;
812

913
beforeEach(() => {
14+
xhr = sinon.useFakeXMLHttpRequest();
15+
1016
config = getConfiguration();
1117
});
1218

1319
afterEach(() => {
1420
let queue = <any>config.queue;
1521
clearInterval(queue._queueTimer);
1622
config = null;
23+
xhr.restore();
1724
});
1825

1926
function getConfiguration(): Configuration {
@@ -38,11 +45,11 @@ describe('DefaultEventQueue', () => {
3845
expect(config.storage.queue.get().length).to.equal(1);
3946
config.queue.process();
4047

41-
if (!(<any>config.queue)._suspendProcessingUntil) {
42-
expect(config.storage.queue.get().length).to.equal(0);
43-
} else {
44-
expect(config.storage.queue.get().length).to.equal(1);
45-
}
48+
config.queue.onEventsPosted((events: IEvent[], response: SubmissionResponse) => {
49+
expect((<any>config.queue)._suspendProcessingUntil).to.be.undefined;
50+
51+
expect(config.storage.queue.get().length).to.equal(0);
52+
});
4653
});
4754

4855
it('should discard event submission', () => {

‎test.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require.config({
22
baseUrl: 'node_modules',
33
paths: {
44
chai: 'chai/chai',
5+
sinon: 'sinon/lib/sinon',
56
TraceKit: 'tracekit/tracekit'
67
}
78
});

0 commit comments

Comments
 (0)
Please sign in to comment.