dimanche 3 juillet 2016

Spying a method which is in the tested module

To make it clear I'll 'draw' you a situation.

Module A(the same javascript file, at my case its reducer in ReactJS/Redux app) contains methods: First, Second

Im testing method First (inside which Second is called - and I want to check whether it has been called or not). So in pseudo code it looks like this:

creating a spy with sinon.spy(module1, 'Second')
invoking First()
checking whether its been called or not _createdSpy.should.have.calledOnce

The problem Ive encountered is that if the method Second is placed at the same module (file) as the First, it doesnt work (library doesnt detect if spy has been called). If I move it to the another file/module, it works just fine.

its by design or Im doing something wrong?

Im using sinon + chai + enzyme stack.

Aucun commentaire:

Enregistrer un commentaire