tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 194 forks source link

Checking for non-existent response header prints full response object #197

Closed alexwhitman closed 10 years ago

alexwhitman commented 10 years ago

Using should 3.1.4, request 2.34.0 with node 0.10.26

var request = require('request');
var should  = require('should');

request.get('http://www.google.co.uk', function(error, response, body) {
    response.should.have.header('foo');
});

the above code prints out the following:

AssertionError: expected { _readableState: 
   { highWaterMark: 16384,
     buffer: [],
     length: 0,
     pipes: null,
     pipesCount: 0,
     flowing: false,
     ended: true,
     endEmitted: true,
     reading: false,
     calledRead: true,
     sync: false,
     needReadable: true,
     emittedReadable: false,
     readableListening: false,
     objectMode: false,
     defaultEncoding: 'utf8',
     ranOut: false,
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },

    <the rest of the `response` object`, many lines, including a `headers` property>

} to have property 'headers'

Firstly the object does have a headers property as response.should.have.header('date'); works fine so the error is wrong, but also printing the entire response object instead of the headers object doesn't seem that useful.

btd commented 10 years ago

Yep, i do not use this assertions and waiting somebody to use. It does not contain custom message for output like others. Btw, do you have any suggestion about custom formatting for this response object? I think to show just headers, what do you think? I usually do this like

response.should.have.property('headers').which.should.have.properties('content-type', ...)
alexwhitman commented 10 years ago

In the 2.x release only the headers object was printed. I'd be happy with the same functionality.

btd commented 10 years ago

I published 3.2.0. It has such message for .header:

AssertionError: expected { ..., headers: { date: 'Sat, 29 Mar 2014 17:37:48 GMT',
  expires: '-1',
  'cache-control': 'private, max-age=0',
  'content-type': 'text/html; charset=ISO-8859-1',
  'set-cookie': 
   [ 'PREF=ID=f118ed90dd3eb019:FF=0:TM=1396114668:LM=1396114668:S=XukWCeEitHLApGlK; expires=Mon, 28-Mar-2016 17:37:48 GMT; path=/; domain=.google.co.uk',
     'NID=67=fY2eqzHYg0bW-9Wi-gB9TiR1ieZKkyeLKMbDPNga7r19KXmc80eEX1GmR10LvHnPW7fLjoYxremBgYtZmsBm91dxOBm3J-NnhiD1LCM-BQa3M4RFPX5G1REYdDiibj0a; expires=Sun, 28-Sep-2014 17:37:48 GMT; path=/; domain=.google.co.uk; HttpOnly' ],
  p3p: 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."',
  server: 'gws',
  'x-xss-protection': '1; mode=block',
  'x-frame-options': 'SAMEORIGIN',
  'alternate-protocol': '80:quic',
  'transfer-encoding': 'chunked' }, ... } to have header 'foo'
    at Assertion.prop.(anonymous function) (/Users/den/Projects/should.js/lib/should.js:61:14)
alexwhitman commented 10 years ago

Just tested it, looks good to me. Thanks.