0

Using the jQuery widget factory, i want to test internally that methods get called. How can I expose those methods to spy on them?

$.widget 'foo',
  _init: ->
    @_bar()

  _bar ->

barSpy = sinon.spy WidgetPluginObject, '_bar'
$('#foo').foo()
expect(barSpy).to.be.called.once

I am looking to reference the widget plugin object (represented here by WidgetPluginObject so I can spy on it's methods.

UPDATE

This is for the purposes of unit testing using mocha/chai; not for any sort of debugging.

brewster
  • 4,342
  • 6
  • 45
  • 67
  • Can you clarify what `'HOW DO I ACCESS THE WIDGET?'` is? Is it a selector, an element, an actual widget instance, or the widget's prototype itself? – Frédéric Hamidi Dec 11 '13 at 00:00
  • that is the missing piece i cannot seem to find. How to I reference the widget object that contains the plugin methods? *editing question* – brewster Dec 11 '13 at 00:43

1 Answers1

-1

I think the term inspect or debug would be more appropriate than spy.

Anyways, you can debug any source code using firebug for firefox or the inspector for Chrome (my favorite).

In the image below if you click on the small arrow next to the title it will expand a menu where you can navigate the document structure to find the javascript. On the right side of the inspector are the debug tools.

To pull up the inspector in Chrome hit F12 or you can right click anywhere on the page and choose inspect element.

enter image description here

The Muffin Man
  • 19,585
  • 30
  • 119
  • 191