Skip to content

Commit

Permalink
Use TestRenderer instead of ShallowRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Aug 17, 2021
1 parent 95f5b6e commit 71b18bb
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import org.scalactic.source.Position
import org.scalatest.{Assertion, Succeeded}
import scommons.nodejs.test.AsyncTestSpec
import scommons.react._
import scommons.react.test.BaseTestSpec
import scommons.react.test.raw.TestRenderer
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._

import scala.concurrent.{Future, Promise}
import scala.scalajs.js
import scala.scalajs.js.JavaScriptException

class TaskManagerSpec extends AsyncTestSpec with BaseTestSpec
with ShallowRendererUtils
with TestRendererUtils {
class TaskManagerSpec extends AsyncTestSpec with BaseTestSpec with TestRendererUtils {

TaskManager.uiComponent = new FunctionComponent[TaskManagerUiProps] {
override protected def render(props: Props): ReactElement = {
Expand All @@ -27,15 +24,22 @@ class TaskManagerSpec extends AsyncTestSpec with BaseTestSpec
TaskManager.uiComponent = null
val props = TaskManagerProps(None)

// suppress intended error
// see: https://github.com/facebook/react/issues/11098#issuecomment-412682721
val savedConsoleError = js.Dynamic.global.console.error
js.Dynamic.global.console.error = { _: js.Any =>
}

//when
val JavaScriptException(error) = the[JavaScriptException] thrownBy {
shallowRender(<(TaskManager())(^.wrapped := props)())
testRender(<(TaskManager())(^.wrapped := props)())
}

//then
s"$error" shouldBe "Error: TaskManager.uiComponent is not specified"

//restore default
js.Dynamic.global.console.error = savedConsoleError
TaskManager.uiComponent = saved
Succeeded
}
Expand Down

0 comments on commit 71b18bb

Please sign in to comment.