airspec: custom assertion
See original GitHub issueIt would be great if airspec support custom assertion feature as in other test frameworks.
One of my usecase of custom assertion is verifying equality of objects in JavaScript world on Scala.js.
Unfortunately, ==
operator does not return true
on a pair of JS objects whose contents are identical, unlike Scala objects (e.g. Seq(1) == Seq(1)
).
It is ofcourse possible to check content-equality when user define a predicate function something like this:
def contentEqual(a: js.Array[_], b: js.Array[_]): Boolean = {
a.length == b.length && (a zip b).forall(_._1 == _._2)
}
test("js array") {
val actual: js.Array[Int] = getA()
assert(contentEqual(actual, Array(1, 2, 3))
}
But this is not helpful on test failure, because it is unclear which element is wrong.
As an user, I expect helpful failure message like [4,5,6] is not equal to [1,2,3]
, which helps debugging.
This feature request may be related to
Power assertion for test failures (e.g., show the condition expression and data differences) #839
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
@exoego This feature is included in Airframe 20.2.0 along with Scala.js 1.0.0 support. Thanks!
Ok. #922 is a PR for this and we need to wait Scala.js 1.0.0 release to use
js.Object.entries
method https://github.com/scala-js/scala-js/pull/3869