testing - Test class instanciation within a method using a spy in Javascript (Jasmine/Mocha) -


i starting test javascipt code , have problem not able solve. have backbone app (amd/requirejs driven) , use mocha (sinon, chai, ...) bdd testing - wraps setup.

let's talking class

class myapp extends app     init: ->         @initcontrollers()      initcontrollers: ->         new headercontroller()         new navcontroller() 

to the first method init, can write following testcase

before ...  describe 'init', ->      'should call @initcontrollers', ->         spy = sinon.spy(@myinstance, 'initcontrollers')         @myinstance.init()         expect(spy.called).tobetruthy() 

this works pretty good. i'd test, if second method initcontrollers creates new instances of headercontroller , navcontroller

how can achieved that? stuck right , little bit confused because start thinking of not right way call controllers.

any appreciated

i confused, @mu-is-to-short gave me right hint

i did now:

describe '@initcontrollers', ->     'should call headercontroller', ->         headercontroller = new headercontroller()         spy = sinon.spy(headercontroller.__proto__, 'initialize')         @myinstance.initcontrollers()         expect(spy.calledonce).tobytruthy() 

it works me, right approach? anyway


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -