Can we make toHaveBeenCalledWith output the toString of an object in error logs?

63 views
Skip to first unread message

Peter Wilkinson

unread,
Aug 24, 2015, 1:05:15 AM8/24/15
to Jasmine
I've got a test that has: 

expect(myObject.myFunction).toHaveBeenCalledWith(anotherObject, andAnotherObject)

When the line passes, all is well. When it fails I get an error that looks like:

Error: Expected spy myFunctionto have been called with [ Object({ log: Logger({ domain: null, _events: Object({  }), _maxListeners: undefined, _level: 20, streams: [ Object({ level: 20, stream: Socket({ _connecting: false, _hadError: false, _handle: [object Pipe], _parent: null, _host: null, _readableState: ReadableState({ objectMode: false, highWaterMark: 16384, buffer: [  ], length: 0, pipes: null, pipesCount: 0, flowing: null, ended: false, endEmitted: false, reading: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null }), readable: false, domain: null, _events: Object({ end: Function, finish: Function, _socketEnd: Function }), _maxListeners: undefined, _writableState: WritableState({ objectMode: false, highWaterMark: 16384, needDrain: false, ending: false, ended: false, finished: false, decodeStrings: false, defaultEncodin

<SNIP>

Add about 1000 lines to the above and you'll have what I've got. It turns out this is because I'm attaching a reference to a Bunyan logger and Jasmine does a JSON.stringify (or something similar) when outputting logs.

It would be great if it would instead use the toString function I've overridden instead when printing logs. Is this possible?

Cheers,
Pete

Gregg Van Hove

unread,
Aug 24, 2015, 9:46:24 AM8/24/15
to jasmi...@googlegroups.com
Jasmine actually looks for a `jasmineToString` function on objects that are being pretty printed for this kind of circumstance. 

We don't use the base `toString` because there may be other reasons in some applications to define a `toString` that isn't useful for testing. 

- Gregg 
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages