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

Make setup of unit tests easier #92

Merged
merged 28 commits into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dbe04f1
ScopeOps are useful -- especially when writing unit tests it is helpf…
svenwiegand Apr 21, 2016
4d68078
Now Angular.injector() is working (angular.injector expects a list of…
svenwiegand Apr 21, 2016
ae92548
Merge branch 'inector-fix'
svenwiegand Apr 21, 2016
2568653
Now Angular.injector() is working (angular.injector expects a list of…
svenwiegand Apr 21, 2016
b3f5aa5
Merge branch 'inector-fix'
svenwiegand Apr 21, 2016
ce360dd
Typesafe and comfort injector.
svenwiegand Apr 21, 2016
09efc88
Merge branch 'scope-ops'
svenwiegand Apr 21, 2016
dfaf285
Merge branch 'injector-fix'
svenwiegand Apr 21, 2016
fd80d11
Merge branch 'injector-typesafe'
svenwiegand Apr 21, 2016
99702c8
Merge branch 'master' of https://github.com/svenwiegand/scalajs-angular
svenwiegand Apr 21, 2016
b927db4
Merge branch 'master' of https://github.com/svenwiegand/scalajs-angular
svenwiegand Apr 21, 2016
974e27e
Merge branch 'injector-typesafe'
svenwiegand Apr 24, 2016
ecf3d65
Merge branch 'injector-fix'
svenwiegand Apr 24, 2016
251113b
Merge branch 'injector-fix'
svenwiegand Apr 24, 2016
9760fab
Merge branch 'injector-fix'
svenwiegand Apr 24, 2016
3d7c44d
Merge branch 'element-fix'
svenwiegand Apr 24, 2016
82682fa
Merge branch 'element-fix'
svenwiegand Apr 24, 2016
5e1d2c3
Merge branch 'jquery'
svenwiegand Apr 24, 2016
4b03e70
Helper to embed templates from HTML source files as `String`.
svenwiegand Apr 24, 2016
6fa5963
Merge branch 'template-embedding'
svenwiegand Apr 24, 2016
5161067
Merge branch 'nameof'
svenwiegand Apr 24, 2016
8f34d1a
Merge branch 'watch-unregister'
svenwiegand Apr 24, 2016
30fd986
Merge remote-tracking branch 'upstream/master'
svenwiegand May 24, 2016
a31ace6
Make unit testing easier.
svenwiegand May 17, 2016
0b64248
Make unit testing easier.
svenwiegand May 24, 2016
7614eaa
Rolling back macro based templates
svenwiegand May 25, 2016
4822e31
Code style
svenwiegand May 29, 2016
2650fa3
Fixed ScalaDoc
svenwiegand May 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/scala/com/greencatsoft/angularjs/Angular.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ object Angular {
def apply(name: String): Option[Module] =
angular.module(name).toOption.map(new Module(_))

def bootstrap(element: Element, modules: String*): Injector = angular.bootstrap(element, modules.toJSArray)

def injector: Injector = angular.injector()

def injector(modules: String*): Injector = angular.injector(modules.toJSArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import scala.scalajs.js.{ UndefOr, | }
@js.native
private[angularjs] trait Angular extends js.Object {

def bootstrap(element: Element, modules: js.Array[String]): Injector = js.native

def injector(): Injector = js.native

def injector(modules: js.Array[String]): Injector = js.native
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/com/greencatsoft/angularjs/test/AngularMocks.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.greencatsoft.angularjs.test

import com.greencatsoft.angularjs.core.Timeout
import com.greencatsoft.angularjs.injectable

import scala.scalajs.js

object AngularMocks {
val ModuleName = "ngMock"

@js.native
@injectable("$timeout")
trait TimeoutMock extends Timeout {

def flush(): Unit = js.native
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.greencatsoft.angularjs.test

import com.greencatsoft.angularjs.core.Injector
import com.greencatsoft.angularjs.{Angular, Module, internal}
import org.scalajs.dom.document

import scala.language.experimental.macros

/** Provides an injector for your test suites.
*
* Setup for example like this:
* {{{
* class MyDirectiveSpec extends FunSpec with AngularTestEnvironment with ScopeOps with MustMatchers {
* override val module = Angular.module("app", Seq("ngAnimate", "ngMaterial")).directive[MyDirective]
* override val moduleName = "app"
*
* describe("MyDirective") {
* it("must render") {
* val scope = inject[RootScope].$new(true)
* scope.dynamic.greeting = "Hello World!"
*
* val tag = """<my-directive greeting="{{greeting}}"></my-directive>"""
* val element = inject[Compile](tag)(scope, null)
* scope.$digest()
*
* element.textContent must be ("Hello World!")
* }
* }
* }
* }}}
*/
trait AngularTestEnvironment {
/** Your angular module to be used during the test.
*
* For example {{{Angular.module("app", Seq("ngAnimate", "ngMaterial")).directive[MyDirective]}}}
*/
val module: Module

/** The name of your application module */
val moduleName: String

/** Injector you can use in your tests to access services.
*
* You may want to use the `inject[A]` method for more readable code.
*/
implicit lazy val injector: Injector = {
val rootElement = document.documentElement
Angular.bootstrap(rootElement, moduleName)
}

/** Provides readable access to angular services.
*
* Example: {{{inject[RootScope].$new(true)}}}
*/
def inject[A](implicit injector: Injector): A = macro internal.Injector.get[A]
}