diff --git a/zio-http/src/main/scala/zhttp/html/Html.scala b/zio-http/src/main/scala/zhttp/html/Html.scala index 2f004a750b..81ed4fa065 100644 --- a/zio-http/src/main/scala/zhttp/html/Html.scala +++ b/zio-http/src/main/scala/zhttp/html/Html.scala @@ -1,5 +1,6 @@ package zhttp.html +import scala.annotation.nowarn import scala.language.implicitConversions /** @@ -22,6 +23,8 @@ object Html { implicit def fromDomElement(element: Dom): Html = Html.Single(element) + implicit def fromUnit(@nowarn unit: Unit): Html = Html.Empty + private[zhttp] case class Single(element: Dom) extends Html private[zhttp] final case class Multiple(children: Seq[Dom]) extends Html diff --git a/zio-http/src/test/scala/zhttp/html/HtmlSpec.scala b/zio-http/src/test/scala/zhttp/html/HtmlSpec.scala index ab040f0ac6..5314f22c5c 100644 --- a/zio-http/src/test/scala/zhttp/html/HtmlSpec.scala +++ b/zio-http/src/test/scala/zhttp/html/HtmlSpec.scala @@ -44,7 +44,13 @@ case object HtmlSpec extends DefaultRunnableSpec { val view = div("Hello!", css := "container" :: Nil) val expected = """
Hello!
""" assert(view.encode)(equalTo(expected.stripMargin)) - }, + } + + suite("implicit conversions")( + test("from unit") { + val view: Html = {} + assert(view.encode)(equalTo("")) + }, + ), ) } }