Skip to content

console.log throws an error for non DOM object that has 'tagName' property #2139

@majuric

Description

@majuric

Karma overwrites native console.log and tries to stringify every attribute it gets passed into it so it can create an output. In the process if it encounters a DOM node or a DOM Element it attempts to serialize it https://github.com/karma-runner/karma/blob/master/client/stringify.js#L41

The problem is that detection of whether something is a DOM Node is very optimistic. I'm faced with a problem when trying to console.log a Backbone.View ( or any view that inherits form a Backbone.View ) because every Backbone.View has 'tagName' attribute, and this causes the following error in Karma because it expects a DOM node, but gets a Backbone.View in stead.

PhantomJS 2.1.1 (Linux 0.0.0) ERROR TypeError: undefined is not a function (evaluating 'target.dispatchEvent(e)') at http://localhost:9877/karma.js:1363

Possible solution is to change the way of checking if something is a DOM Node / Element http://stackoverflow.com/a/4754156/3193466

Expected behavior

var V = new Backbone.View(); console.log( V )
// Will output the View object in the console

Actual behavior

var V = new Backbone.View(); console.log( V )
`PhantomJS 2.1.1 (Linux 0.0.0) ERROR
TypeError: undefined is not a function (evaluating 'target.dispatchEvent(e)')
at http://localhost:9877/karma.js:1363``

Enviroment Details

  • Karma version (output of karma --version): Karma version: 0.13.22
  • Relevant part of your karma.config.js file: Nothing specific

Steps to reproduce the behaviour

  1. Instantiate a Backbone.View ( Or use any object that has 'tagName' attribute' )
  2. console.log the instance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions