Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Mock classes for testing and controller/service/factory/etc. types #31

Open
dainkaplan opened this issue Feb 7, 2015 · 3 comments
Open

Comments

@dainkaplan
Copy link

Howdy,

Your angular-is bindings for Scala-js looks very promising! I have an implementation question that relates to testing. You opted for using Scala objects for defining controllers and the like, with annotations on vars which a macro then goes ahead and fills in and deals with creating the instances. This however, isn't easily testable directly in Scala. I was wondering why you didn't go with something simpler, like

// marker trait
trait Controller

class FooController(@dep("$scope") scope: Scope, @dep("$filter") filter: Filter) extends Controller {
    // initialization code here
}

to declare new controllers. This would allow mocking all the traits and creating unit tests directly by instantiating instances in Scala.

I'm sure there is a reason you did it how you did it, so I was hoping you could elaborate. It would be nice to create unit tests!

@mysticfall
Copy link
Member

Hi,

I actually do agree with your concerns because I hate to use vars myself for the purpose of the DI (as well as the testability issue you mentioned). The reason it was implemented this way is just that the macro based annotation support was introduced only in the recent version, so there was no easy way to implement constructor based DI without it.

I'm inclined to support constructor based DI even if it involves breaking backward compatibility. I'll see if it's feasible to implement it in the next release. But as I'm quite occupied with other projects now, I'm afraid I can't make any promise yet.

Anyway, thanks for bringing this up!

@dainkaplan
Copy link
Author

Have you seen Scalajs-Angulate? It provides the exact kind of constructor macros I was asking about. I don't know about testing yet, though.

@mysticfall
Copy link
Member

Yes, and I think he's heading toward the right direction. I haven't seen the code yet, but I suppose I should compare our code base later and see if I could get some ideas.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants