jeudi 23 avril 2015

test *initilization* of factory or service in jasmine

I'm using Angular, and we have a factory which does some initialization of restangular defaults. It's responsible for adding a number of hooks into restangular paths for later.

I want to test the logic of this factory, but the problem is that most of the hooks are set before the factory is returned, their done once at initialization. As such I don't know how to test the logic. I can't add a spy, because by the time I have a factory object it's already been initialized and it's too late to test that init logic.

I can test that specific paths received the expected hooks, but I feel like that not a proper unit level test. Since were adding a number of general helper methods to every one of our paths I would really like to test in isolation that each general helper function was added done, in a way that is not depending on any of the other hooks we set specific to individual paths.

Is there a good way to plug in to Angular and test the init logic that occurs before a factory is returned? I would like to either modify a default array (the one that associates paths to specific hooks), or to be able to call helper functions in isolation.

Aucun commentaire:

Enregistrer un commentaire