Skip to content

Commit cc5a25f

Browse files
committed
Add ConsoleHijackTest
1 parent 575fe6f commit cc5a25f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

library/project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ object ScalaJsReact {
251251

252252
lazy val util = project
253253
.dependsOn(utilFallbacks % Provided)
254-
.configure(commonSettings, publicationSettings, hasNoTests, disableScalaDoc3, prohibitDefaultEffects)
254+
.configure(commonSettings, publicationSettings, utestSettings, disableScalaDoc3, prohibitDefaultEffects)
255255
.settings(
256256
libraryDependencies += Dep.scalaJsDom.value,
257257
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package japgolly.scalajs.react.util
2+
3+
import org.scalajs.dom.console
4+
import scala.util.Try
5+
import utest._
6+
7+
object ConsoleHijackTest extends TestSuite {
8+
9+
override def tests = Tests {
10+
"catchReactWarnings" - {
11+
12+
def testPass[A](a: => A): A =
13+
ConsoleHijack.fatalReactWarnings(a)
14+
15+
def testThrows(a: => Any): Unit = {
16+
val t = Try(ConsoleHijack.fatalReactWarnings(a))
17+
println(t)
18+
assert(t.isFailure)
19+
}
20+
21+
"error_hit" - testThrows(console.error("Warning: this is a test"))
22+
"error_miss" - testPass(console.error("this is a test"))
23+
"warn_hit" - testPass(console.warn("Warning: this is a test"))
24+
"warn_miss" - testPass(console.warn("this is a test"))
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)