demostrate restream more clearly in tests

This commit is contained in:
David Frank 2016-03-23 15:23:56 +08:00
parent 89ce1b70b6
commit 4d63427123
1 changed files with 17 additions and 4 deletions

View File

@ -800,13 +800,26 @@ describe('node-fetch', function() {
});
});
it('should allow cloning a json response, and log it as text response', function() {
it('should allow cloning a json response and log it as text response', function() {
url = base + '/json';
return fetch(url).then(function(res) {
var r1 = res.clone();
return fetch.Promise.all([r1.text(), res.json()]).then(function(results) {
expect(results[0]).to.equal('{"name":"value"}');
expect(results[1]).to.deep.equal({name: 'value'});
return fetch.Promise.all([res.json(), r1.text()]).then(function(results) {
expect(results[0]).to.deep.equal({name: 'value'});
expect(results[1]).to.equal('{"name":"value"}');
});
});
});
it('should allow cloning a json response, and then log it as text response', function() {
url = base + '/json';
return fetch(url).then(function(res) {
var r1 = res.clone();
return res.json().then(function(result) {
expect(result).to.deep.equal({name: 'value'});
return r1.text().then(function(result) {
expect(result).to.equal('{"name":"value"}');
});
});
});
});