4

I had written components using Binding.scala and they're working fine for me. Now I want to unit test them using ScalaTest. How to unit test them?

I had taken reference from Binding.scala's unit tests. However it's not working for me as get and valuemethods are not accessible.

Mitesh
  • 477
  • 1
  • 6
  • 22

1 Answers1

1

In current version of Binding.scala (11.8.1) you can use this method for unit testing:

  "Comment" in {
    @dom def comment = <div><!--my comment--></div>
    val div = document.createElement("div")
    dom.render(div, comment)
    assert(div.innerHTML == "<div><!--my comment--></div>")
  }

Unfortunately, you couldn't write such (more performant?) tests:

  "TextElement" in {
    @dom val monadicDiv: Binding[Div] = <div>text</div>
    monadicDiv.watch()
    assert(monadicDiv.get.outerHTML == "<div>text</div>")
  }

because of Binding.get/Binding.value is private/protected. I filled issue about this https://github.com/ThoughtWorksInc/Binding.scala/issues/217

lmars
  • 302
  • 1
  • 6
  • In the new [html.scala](https://github.com/GlasslabGames/html.scala), there is a `NodeBinding` type, which has a public `value` to access the raw HTML object. See https://github.com/GlasslabGames/html.scala#getting-started – Yang Bo Nov 03 '21 at 04:51