Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
danmarshall committed Aug 25, 2016
2 parents 179fd73 + c6e2434 commit 3669375
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,33 @@ describe('Observable.ajax', () => {
expect(complete).to.be.true;
});

it('should succeed on 204 No Content', () => {
const expected = null;
let result;
let complete = false;

Rx.Observable
.ajax.get('/flibbertyJibbet')
.subscribe(x => {
result = x.response;
}, null, () => {
complete = true;
});

const request = MockXMLHttpRequest.mostRecent;

expect(request.url).to.equal('/flibbertyJibbet');

request.respondWith({
'status': 204,
'contentType': 'application/json',
'responseText': expected
});

expect(result).to.deep.equal(expected);
expect(complete).to.be.true;
});

it('should able to select json response via getJSON', () => {
const expected = { foo: 'bar' };
let result;
Expand Down Expand Up @@ -469,6 +496,7 @@ describe('Observable.ajax', () => {
});

describe('ajax.post', () => {

it('should succeed on 200', () => {
const expected = { foo: 'bar', hi: 'there you' };
let result: Rx.AjaxResponse;
Expand Down Expand Up @@ -501,5 +529,38 @@ describe('Observable.ajax', () => {
expect(result.response).to.deep.equal(expected);
expect(complete).to.be.true;
});

it('should succeed on 204 No Content', () => {
const expected = null;
let result: Rx.AjaxResponse;
let complete = false;

Rx.Observable
.ajax.post('/flibbertyJibbet', expected)
.subscribe(x => {
result = x;
}, null, () => {
complete = true;
});

const request = MockXMLHttpRequest.mostRecent;

expect(request.method).to.equal('POST');
expect(request.url).to.equal('/flibbertyJibbet');
expect(request.requestHeaders).to.deep.equal({
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
});

request.respondWith({
'status': 204,
'contentType': 'application/json',
'responseText': expected
});

expect(result.response).to.deep.equal(expected);
expect(complete).to.be.true;
});

});
});

0 comments on commit 3669375

Please sign in to comment.