{"id":15369306,"url":"https://github.com/raquo/scala-dom-testutils","last_synced_at":"2025-04-15T13:43:25.723Z","repository":{"id":24445917,"uuid":"101583627","full_name":"raquo/scala-dom-testutils","owner":"raquo","description":"Test that your DOM nodes / HTML elements match your expectations in a type-safe way","archived":false,"fork":false,"pushed_at":"2025-02-16T23:58:14.000Z","size":137,"stargazers_count":13,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T20:45:35.917Z","etag":null,"topics":["dom","html","jsdom","scala","scalajs","scalatest","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raquo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-27T22:15:58.000Z","updated_at":"2025-02-16T23:58:18.000Z","dependencies_parsed_at":"2024-01-06T02:23:16.710Z","dependency_job_id":"69456a73-fb04-49c2-b02d-92345948c367","html_url":"https://github.com/raquo/scala-dom-testutils","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raquo%2Fscala-dom-testutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raquo%2Fscala-dom-testutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raquo%2Fscala-dom-testutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raquo%2Fscala-dom-testutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raquo","download_url":"https://codeload.github.com/raquo/scala-dom-testutils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249082083,"owners_count":21209804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","html","jsdom","scala","scalajs","scalatest","testing","testing-tools"],"created_at":"2024-10-01T13:35:05.967Z","updated_at":"2025-04-15T13:43:25.696Z","avatar_url":"https://github.com/raquo.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scala DOM Test Utils\n[![Build status](https://github.com/raquo/scala-dom-testutils/actions/workflows/test.yml/badge.svg)](https://github.com/raquo/scala-dom-testutils/actions/workflows/test.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/com.raquo/domtestutils_sjs1_3.svg)](https://search.maven.org/artifact/com.raquo/domtestutils_sjs1_3)\n\n\n_Scala DOM Test Utils_ provides a convenient, type-safe way to assert that a real Javascript DOM node matches a certain description using an extensible DSL.\n\n    \"com.raquo\" %%% \"domtestutils\" % \"\u003cversion\u003e\"  // Scala.js\n\nYou can use _Scala DOM Test Utils_ either directly to make assertions, or you if you're writing a DOM construction / manipulation library, to power its own test utils package.\n\n\n\n## Project Status\n\nThis project exists only to serve the needs of testing [Laminar](https://github.com/raquo/Laminar) and the basic needs of testing Laminar applications. Emphasis on _basic_. This is not going to be a full fledged test kit, nor are there any guarantees of documentation or stability. If you want a something more, you'll need to fork this and/or create your own. It's a very small project anyway.\n\n**I am very unlikely to accept PRs on this project** – please talk to me before spending your time.\n\n\n\n## Example Test\n\n```scala\nimport com.raquo.laminar.api.L._\n\n// Create a JS DOM node that you want to test (example shows optional Laminar syntax)\nval jsDomNode: org.scalajs.dom.Node = div(\n  rel := \"yolo\"\n  span(\"Hello, \"),\n  p(\"bizzare \", a(href := \"http://y2017.com\", \"2017\"), span(\" world\")),\n  hr\n).ref \n \n// Mount the DOM node for testing\nmount(jsDomNode, \"optional clue to show on failure\")\n \n// Assert that the mounted node matches the provided description (this test will pass given the input above)\nexpectNode(\n  div.of(\n    rel is \"yolo\", // Ensure that rel attribute is \"yolo\". Note: assertions for properties and styles work similarly \n    span.of(\"Hello, \"), // Ensure the this element contains just one text node: \"Hello, \"\n    p.of(\n      \"bizzare \",\n      a.of(\n        href is \"http://y2017.com\",\n        title.isEmpty, // Ensure that title attribute is not set\n        \"2017\"\n      ),\n      span.of(\" world\")\n    ),\n    hr // Just check existence of element and tag name. Equivalent to `hr like ()` \n  )\n)\n```\n\nThe above example gets `div`, `rel`, `href`, etc. from Laminar, and uses implicit conversions from these Laminar values to DOM TestUtils classes like `ExpectedNode` and `TestableHtmlAttr`.See more usage examples and glue code in [Laminar tests](https://github.com/raquo/Laminar/tree/master/src/test/scala/com/raquo/laminar)\n\nLaminar is not required to use Scala DOM TestUtils. You can integrate similarly with any other Scala.js UI library.\n\n\n\n## Usage\n\nCanonical usage is to `mount` one DOM node / tree (e.g. the output of your component) and then test it using the `expectNode` method.\n\nAlternative is to call `expectNode(actualNode, expectedNode)`, for example if you only want to test a subtree of what you mounted.\n\nIf the mechanics of `MountOps` do not work for you, you can bypass `MountOps` altogether and just call `ExpectedNode.checkNode(actualNode)` directly to get a list of errors.\n\n**With ScalaTest**: Your test suite should extend the `MountSpec` trait. Use `mount` and `expectNode` methods in your test code. You can call `unmount` and then `mount` again within one test if you want to test multiple unrelated nodes (e.g. different variations in a loop). See Laminar's test suite for an example.\n\n**Without ScalaTest**: You could write a tiny adapter like `MountSpec` for your test framework, which would:\n \n- Extend `MountOps` and provide `doAssert` / `doFail` implementations specific to your test framework\n- Call `resetDOM` in the beginning of each test, and `clearDOM` at the end of each test.\n- However, this project depends on ScalaTest, currently just for the `source.Position` macro, but in the future the integration could be deepened.\n- So, long term, you might be better off forking this project if you want to use a different testing library.\n- You could probably also forgo `MountOps` and other such files and drop down to calling `ExpectedNode.checkNode(actualNode)` to get a list of errors, and build your own test util around it.\n\n\n\n## Versioning\n\nThere is no promise of any backwards compatibility in this particular project. I _roughly_ align versions with Scala DOM Types for my own convenience.\n\n\n\n## My Related Projects\n\n- [Laminar](https://github.com/raquo/Laminar) – Reactive UI library based on _Scala DOM Types_\n- [Scala DOM Types](https://github.com/raquo/scala-dom-types) – Type definitions for all the HTML tags, attributes, properties, and styles, used by Laminar and a few other similar libraries\n\n\n\n## Author\n\nNikita Gazarov – [@raquo](https://twitter.com/raquo)\n\nLicense – MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraquo%2Fscala-dom-testutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraquo%2Fscala-dom-testutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraquo%2Fscala-dom-testutils/lists"}