source: trip-planner-front/node_modules/needle/test/mimetype.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1var should = require('should'),
2 needle = require('./../'),
3 helpers = require('./helpers');
4
5describe('receiving json and xml content as string', function() {
6
7 this.timeout(5000);
8
9 ["text/plain", "application/json", "application/ld+json", "application/xml", "image/svg+xml"].forEach(function(mimetype, offset){
10
11 describe('Given content-type: "'+mimetype+'"', function () {
12
13 var server, port = 54330+offset;
14
15 before(function(done) {
16 server = helpers.server({
17 port: port,
18 response: 'content',
19 headers: { 'Content-Type': mimetype }
20 }, done);
21 })
22
23 after(function(done) {
24 server.close(done)
25 })
26
27 describe('with parse = false', function () {
28 it('delivers by default as string', function (done) {
29
30 needle.get('http://localhost:' + port, { parse: false }, function (err, resp) {
31
32 resp.body.should.be.a.String;
33 (typeof resp.body).should.eql('string')
34 done();
35 })
36
37 })
38
39 })
40
41 })
42
43 });
44
45 ["application/octet-stream", "image/png"].forEach(function(mimetype, offset){
46
47 describe('Given content-type: "'+mimetype+'"', function () {
48
49 var server, port = 54340+offset;
50
51 before(function(done) {
52 server = helpers.server({
53 port: port,
54 response: 'content',
55 headers: { 'Content-Type': mimetype }
56 }, done);
57 })
58
59 after(function(done) {
60 server.close(done)
61 })
62
63 describe('with parse = false', function () {
64 it('delivers by default as Buffer', function (done) {
65
66 needle.get('http://localhost:' + port, { parse: false }, function (err, resp) {
67
68 resp.body.should.be.a.Buffer;
69 (resp.body instanceof Buffer).should.eql(true)
70 done();
71 })
72
73 })
74
75 })
76
77 })
78
79 })
80
81})
Note: See TracBrowser for help on using the repository browser.