japgolly on master
Update docs for changes in 1.4.0 (compare)
japgolly on v1.4.0
japgolly on master
Towards v1.4.1 (compare)
japgolly on master
Prepare for v1.4.0 Upgrade React to 16.6.3 React.lazy and 85 more (compare)
japgolly on v1.4.x
Add note about Reusability/Reus… doc formatting Prepare to release v1.4.0 (compare)
japgolly on v1.4.x
Test AsyncCallback.init Update Travis CI caching (compare)
japgolly on v1.4.x
Update Travis CI cache dirs Revise changelog (compare)
Hi all,
I need some help setting up my first unit test for sjs react. I have the following test:
import utest._
.....
object TestTest extends TestSuite {
val tests: Tests = Tests {
"plainElement" - {
val re: VdomElement = <.div("Good")
val c = ReactTestUtils.renderIntoDocument(re)
test(c, """<div>Good</div>""")
}
}
}
When I run it I get this error:
- TestTest.plainElement.0 2ms
scala.scalajs.js.JavaScriptException: ReferenceError: document is not defined
<jscode>.Object.renderIntoDocument(react-dom-test-utils.development.js:1163)
japgolly.scalajs.react.test.ReactTestUtils$.renderIntoDocument(ReactTestUtils.scala:66)
<jscode>.array$9(Chicken.scala:51)
scala.scalajs.runtime.AnonFunction0.apply(AnonFunctions.scala:22)
So renderIntoDocument
is erroring as there are no documents to render to.
Does anyone know what is causing this?
In the setup
section of this page: https://github.com/japgolly/scalajs-react/blob/master/doc/TESTING.md#test-scripts
it says:// React JS itself.
// NOTE: Requires react-with-addons.js instead of just react.js
I am not entirely sure what that means and how to set up the reacts addson via the scalajs-bundler
Any help will be much appreciated
In addition to the above, I have also tried using test-state
.
Things are starting to get really frustrating for me.
My test (copied from the test-state
example) fail with this error:
-------------------------------- Running Tests --------------------------------
X app.TodoTest 0ms
scala.scalajs.js.JavaScriptException: ReferenceError: Sizzle is not defined
teststate.domzipper.sizzle.Exports.$init$(Exports.scala:7)
app.MyTestState$.<init>(MyTestState.scala:8)
app.MyTestState$.<clinit>(MyTestState.scala:8)
app.TodoTestDsl$.<init>(TodoTestDsl.scala:68)
app.TodoTestDsl$.<clinit>(TodoTestDsl.scala:58)
app.TodoTest$.<init>(TodoTest.scala:16)
app.TodoTest$.<clinit>(TodoTest.scala:8)
<jscode>.{anonymous}()(TodoTest.scala:8)
scala.scalajs.reflect.LoadableModuleClass.loadModule(Reflect.scala:24)
utest.PlatformShims$.loadModule(PlatformShims.scala:26)
[info]
[error] Failed tests:
[error] app.TodoTest
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 3 s, completed 07-Sep-2020 17:32:07
sbt:client>
This is my sbt:
lazy val client = (project in file("client"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalaJSBundlerPlugin)
.settings(
scalaJSUseMainModuleInitializer := true,
libraryDependencies ++= Seq(
"com.github.japgolly.scalajs-react" %%% "core" % "1.7.5",
"com.github.japgolly.scalajs-react" %%% "extra" % "1.7.5",
"com.github.japgolly.scalacss" %%% "ext-react" % "0.6.1",
"com.lihaoyi" %%% "upickle" % "1.2.0",
"io.suzaku" %%% "diode-react" % "1.1.13",
"com.lihaoyi" %%% "autowire" % "0.3.2",
"com.github.japgolly.scalajs-react" %%% "test" % "1.7.5" % Test,
"org.querki" %%% "jquery-facade" % "2.0" % Test,
"com.lihaoyi" %%% "utest" % "0.7.5" % Test,
// "com.github.japgolly.test-state" %%% "core" % TestStateVer % "test",
// "com.github.japgolly.test-state" %%% "dom-zipper" % TestStateVer % "test",
"com.github.japgolly.test-state" %%% "dom-zipper-sizzle" % TestStateVer % "test",
"com.github.japgolly.test-state" %%% "ext-scalajs-react" % TestStateVer % "test",
"com.github.julien-truffaut" %%% "monocle-core" % "2.0.4",
"com.github.julien-truffaut" %%% "monocle-macro" % "2.0.4",
"com.github.japgolly.scalajs-react" %%% "ext-monocle-cats" % "1.7.5",
"org.scala-js" %%% "scalajs-java-time" % "1.0.0" % Test
),
npmDependencies in Compile ++= Seq(
// "sizzle" → "2.3.0",
"react" -> "16.13.1",
"react-dom" -> "16.13.1",
"bootstrap" → "4.5.2",
"jquery" → "1.9.1",
"popper.js" → "1.16.1"
)
)
.settings(addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.1" cross CrossVersion.full))
.settings(testFrameworks += new TestFramework("utest.runner.Framework"))
Can someone please give me hand to resolve these issues?
This is now fixed:
When I run it I get this error:
- TestTest.plainElement.0 2ms scala.scalajs.js.JavaScriptException: ReferenceError: document is not defined <jscode>.Object.renderIntoDocument(react-dom-test-utils.development.js:1163) japgolly.scalajs.react.test.ReactTestUtils$.renderIntoDocument(ReactTestUtils.scala:66) <jscode>.array$9(Chicken.scala:51) scala.scalajs.runtime.AnonFunction0.apply(AnonFunctions.scala:22)
So
renderIntoDocument
is erroring as there are no documents to render to.
Does anyone know what is causing this?
This was fixed by adding requireJsDomEnv in Test := true
to build.sbt
Sizzle is not defined
)
com.github.japgolly.test-state" %%% "dom-zipper-sizzle
dependency to work
@arminio if you provide a link maybe someone else can
Sack
though, it's pretty funny that you're peeking around there. I'm gonna guess that you inspected a type and the IDE dealiased the type for you. As you can see from the subtypes, a Sack
is a value, a recursive product or a recursive coproduct. @nafg made an educated guess that it's related to typeclass derivation but it's actually the structure of all composable concepts in Test State. Users are not supposed to know about it because it's part of the internal API and you never interact with it directly. The public types that you should know about are documented here https://github.com/japgolly/test-state/blob/master/doc/TYPES.md and under-the-hood, some of them dealias to Sack
s. If you want to be explicit about your Test State types, use the type members provided on your dsl
object. This is an example: https://github.com/japgolly/test-state/blob/master/example-react/src/test/scala/teststate/example/react/TodoTestDsl.scala#L76
dsl.Action
vs dsl.Actions
; the type is always the plural form even if the value contains only one action.
JSDependenciesPlugin
scalajs-react
?
So it seems some of the documentation has become stale in the post-Scala.JS-1.0-world, @arminio it'd be really appreciated if you would kindly submit a PR, or even an issue with a list of changes you had to make, so that we can update the doc for future users.
@japgolly PR for a small update to the test-state
documentation raised:
japgolly/test-state#144
CallbackKleisli
and then call .toJsFn
. (1) is nice and simple and (2) is a great option if you're doing lots of composition but in many cases it's likely to just be over-engineering for no benefit so you'll have to access your situation and choose whichever's best. Hope that helps