Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/exoego/scalajs-test-helper
Useful assertions for testing Scala.js
https://github.com/exoego/scalajs-test-helper
munit scala-js scalatest
Last synced: 3 months ago
JSON representation
Useful assertions for testing Scala.js
- Host: GitHub
- URL: https://github.com/exoego/scalajs-test-helper
- Owner: exoego
- License: mit
- Created: 2020-01-28T00:25:17.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-28T15:42:52.000Z (7 months ago)
- Last Synced: 2024-06-28T17:09:24.390Z (7 months ago)
- Topics: munit, scala-js, scalatest
- Language: Scala
- Homepage:
- Size: 390 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Scala.js Test Helper
----This project provides custom assertions and other helpers, which are convenient for writing test in Scala.js.
## Usage
### With [ScalaTest](http://www.scalatest.org)
The `scalajs-test-helper-scalatest` library is available for Scala.js 0.6.x and 1.0.0.
```scala
libraryDependencies += "net.exoego" %%% "scalajs-test-helper-scalatest" % "0.2.0" % Test
```Import `net.exoego.scalajs.scalatest.structural._`.
This imports some [custom `Equality`](http://www.scalactic.org/user_guide/CustomEquality) implementations for JavaScript objects (e.g. `js.Object` and `js.Array`).
Those allows comparing two JS objects based on its contents, as similar as comparing Scala objects.```scala
import org.scalatest.funsuite.AnyFunSuite
import scala.scalajs.jsclass JsObjectStructuralEqualityTest extends AnyFunSuite {
import net.exoego.scalajs.scalatest.structural._test("content equal of js.Array") {
assert(js.Array() != js.Array())assert(js.Array() === js.Array())
assert(js.Array(1, "a") === js.Array(1, "a"))
assert(js.Array(new js.Object()) === js.Array(new js.Object()))
}
}
```### With [MUnit](https://scalameta.org/munit/)
The `scalajs-test-helper-munit` library is available for Scala.js 0.6.x and 1.0.0.
```scala
libraryDependencies += "net.exoego" %%% "scalajs-test-helper-munit" % "0.2.0" % Test
```Import `net.exoego.scalajs.munit.ScalaJSAssertions` and extend it by your Test class.
Those allows comparing two JS objects based on its contents, as similar as comparing Scala objects.```scala
import scala.scalajs.js
import net.exoego.scalajs.munit.ScalaJSAssertionsclass JsObjectStructuralEqualityTest extends munit.FunSuite with ScalaJSAssertions {
test("content equal of js.Array") {
assertStructuralEquals(js.Array(), js.Array())
assertStructuralEquals(js.Array(1, "a"), js.Array(1, "a"))
assertStructuralEquals(js.Array(new js.Object()), js.Array(new js.Object()))assertNotStructuralEquals(js.Array(0, "b"), js.Array(1, "a"))
}
}
```### Other test library
Not supported but welcome contributions.