{"id":32306931,"url":"https://github.com/mariposa-dart/test","last_synced_at":"2026-07-12T20:31:07.764Z","repository":{"id":56834443,"uuid":"138649518","full_name":"mariposa-dart/test","owner":"mariposa-dart","description":"Infrastructure for unit-testing Mariposa widgets.","archived":false,"fork":false,"pushed_at":"2018-08-30T03:58:25.000Z","size":25,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-25T13:03:30.322Z","etag":null,"topics":["dart","mariposa","testing","unit-testing"],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/mariposa_test","language":"Dart","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/mariposa-dart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-25T20:59:31.000Z","updated_at":"2019-10-06T23:57:13.000Z","dependencies_parsed_at":"2022-09-08T07:41:46.191Z","dependency_job_id":null,"html_url":"https://github.com/mariposa-dart/test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mariposa-dart/test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariposa-dart%2Ftest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariposa-dart%2Ftest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariposa-dart%2Ftest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariposa-dart%2Ftest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mariposa-dart","download_url":"https://codeload.github.com/mariposa-dart/test/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariposa-dart%2Ftest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35402741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-12T02:00:06.386Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["dart","mariposa","testing","unit-testing"],"created_at":"2025-10-23T07:12:26.445Z","updated_at":"2026-07-12T20:31:07.759Z","avatar_url":"https://github.com/mariposa-dart.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mariposa_test\n[![Pub](https://img.shields.io/pub/v/mariposa_test.svg)](https://pub.dartlang.org/packages/mariposa_test)\n[![build status](https://travis-ci.org/mariposa-dart/test.svg)](https://travis-ci.org/mariposa-dart/test)\n\nInfrastructure for unit-testing Mariposa widgets:\n* The `DomTester` class, which can interactively run tests against a tree, supporting events\nand DOM traversal.\n* Multiple `Matcher` functions that can be used in unit tests.\n* `convertNode`, which converts a `package:html` `Node` to a\n`package:html_builder` `Node`.\n\nFor best results, use `package:test`. \n\n# `DomTester`\nThose familiar with Flutter's `WidgetTester` will understand the `DomTester` class.\nThis class renders Mariposa widgets into an AST from `package:html`, which can then be interacted\nwith, as though it were a real browser DOM. Oof course, things like Web API's will be unavailable\nfrom a command-line setting, but the best practice is to use abstraction to mock these things in\nat testing time, anyways.\n\nThe `DomTester` API is more or less the same as `mariposa/dom` or `mariposa/string`:\n\n```dart\nimport 'dart:async';\nimport 'package:html_builder/elements.dart';\nimport 'package:mariposa/mariposa.dart';\nimport 'package:mariposa_test/mariposa_test.dart';\nimport 'package:test/test.dart';\n\nvoid main() {\n  DomTester tester;\n\n  var app = () {\n    return div(\n      c: [\n        h1(\n          id: 'foo',\n          className: 'heading',\n          c: [text('H1!!!')],\n        ),\n        myWidget(),\n        myOtherWidget(),\n      ],\n    );\n  };\n\n  setUp(() {\n    tester = new DomTester()..render(app);\n  });\n\n  tearDown(() =\u003e tester.close());\n}\n```\n\nHowever, `DomTester` exposes the following functionality for easy testing:\n\n* `getElementById`\n* `querySelector`\n* `querySelectorAll`\n* `fire` - Fire an event from an element\n* `nextEvent` - Listen for the next event of a specific type fired by an element\n\n`DomTester` methods deal with objects of the type `DomTesterElement`, which has a property\n`nativeElement` that points to a `package:html` element. For complex functionality, feel free\nto use this provision.\n\n```dart\nvoid main() {\n  test('getElementById', () {\n      expect(tester.getElementById('foo'), h1Element);\n    });\n  \n    test('getElementsByClassName', () {\n      expect(tester.getElementsByClassName('heading'), contains(h1Element));\n    });\n  \n    test('getElementsByTagName', () {\n      expect(tester.getElementsByTagName('h1'), contains(h1Element));\n    });\n  \n    test('querySelector', () {\n      expect(h1Element?.nativeElement?.text, 'H1!!!');\n    });\n  \n    test('querySelectorAll', () {\n      expect(tester.querySelectorAll('.heading'), contains(h1Element));\n    });\n    \n    test('fire', () {\n      tester.fire(h1Element, 'the event', someData);\n    });\n    \n    test('handle click', () async {\n      var ev = await tester.nextEvent(h1Element, 'the event');\n      expect(ev, isNotNull);\n    });\n}\n```\n\n# Matchers\nAll of the below `Matcher` functions accept either concrete objects, or\n`Matcher` instances; therefore, they can be combined together.\n\n## Single-node\n* `hasTagName` - Matches a node's tag name\n* `hasAttributes` - Matches a node's attributes\n* `hasChildren` - Matches a node's children\n* `hasClass` - Matches a node's `class` attribute\n* `hasClassString` - Matches a node's `class` attribute, after transforming it to a `String`\n* `hasClassList` - Matches a node's `class` attribute, after transforming it to a `List\u003cString\u003e`\n\n```dart\nvoid main() {\n  test('hasTagName', () {\n    expect(br(), hasTagName('br'));\n  });\n\n  test('hasAttributes', () {\n    expect(\n      h('p', {'foo': 'bar', 'baz': 'quux'}),\n      allOf(\n        hasAttributes(containsPair('foo', 'bar')),\n        isNot(hasAttributes(containsPair('foo', 'baz'))),\n      ),\n    );\n  });\n\n  test('hasChildren', () {\n    expect(\n      div(c: [br()]),\n      allOf(\n        hasChildren(anyElement(rendersTo('\u003cbr\u003e'))),\n        isNot(hasChildren(anyElement(rendersTo('\u003chr\u003e')))),\n      ),\n    );\n  });\n  \n  test('hasClassList', () {\n    expect(\n      h('a', {'class': 'b c'}),\n      allOf(\n        hasClassList(['b', 'c']),\n        isNot(hasClassList(['d'])),\n      ),\n    );\n  });\n}\n```\n\n## Two-node\n* `rendersTo` - Asserts that a node renders to a given HTML string or `Matcher`.\n* `rendersEqualTo` - Asserts that two nodes produce the same output.\n\n```dart\nvoid main() {\n    test('rendersTo', () {\n      expect(\n        div(c: [br()]),\n        allOf(\n          rendersTo('\u003cdiv\u003e\u003cbr\u003e\u003c/div\u003e'),\n          isNot(rendersTo('\u003cdip\u003e\u003chr\u003e\u003c/dip\u003e')),\n        ),\n      );\n    });\n  \n    test('rendersEqualTo', () {\n      expect(\n        div(c: [br()]),\n        allOf(\n          rendersEqualTo(div(c: [br()])),\n          rendersEqualTo(h('div', {}, [br()])),\n          isNot(rendersEqualTo(p())),\n        ),\n      );\n    });\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariposa-dart%2Ftest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariposa-dart%2Ftest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariposa-dart%2Ftest/lists"}