{"id":16426768,"url":"https://github.com/wasabeef/flutter_hooks_test","last_synced_at":"2025-10-11T11:05:06.677Z","repository":{"id":40435139,"uuid":"441076652","full_name":"wasabeef/flutter_hooks_test","owner":"wasabeef","description":"Simple and complete Flutter hooks testing utilities that encourage good testing practices.","archived":false,"fork":false,"pushed_at":"2024-10-17T20:15:28.000Z","size":515,"stargazers_count":31,"open_issues_count":5,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-20T06:44:30.152Z","etag":null,"topics":["dart","flutter","flutter-hooks","react-hooks","testing"],"latest_commit_sha":null,"homepage":"","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/wasabeef.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wasabeef","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-12-23T05:51:34.000Z","updated_at":"2024-10-09T06:07:44.000Z","dependencies_parsed_at":"2023-11-11T17:26:23.433Z","dependency_job_id":"0fadc640-6098-4b25-a093-a8d9cd36a097","html_url":"https://github.com/wasabeef/flutter_hooks_test","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabeef%2Fflutter_hooks_test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabeef%2Fflutter_hooks_test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabeef%2Fflutter_hooks_test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabeef%2Fflutter_hooks_test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasabeef","download_url":"https://codeload.github.com/wasabeef/flutter_hooks_test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221666411,"owners_count":16860415,"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":["dart","flutter","flutter-hooks","react-hooks","testing"],"created_at":"2024-10-11T08:10:15.904Z","updated_at":"2025-10-11T11:05:06.672Z","avatar_url":"https://github.com/wasabeef.png","language":"Dart","funding_links":["https://github.com/sponsors/wasabeef"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eFlutter Hooks Testing Library\u003c/h1\u003e\n    \u003ca href=\"https://www.emojione.com\"\u003e\n        \u003cimg\n            height=\"128\"\n            width=\"128\"\n            alt=\"fishing pole\"\n            src=\"https://raw.githubusercontent.com/wasabeef/flutter_hooks_test/main/art/fishing_pole.gif\" /\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cp\u003eSimple and complete Flutter hooks testing utilities that encourage good testing practices.\u003c/p\u003e\n    \u003cstrong\u003eInspired by \u003ca href=\"https://react-hooks-testing-library.com/\"\u003ereact-hooks-testing-library\u003c/a\u003e.\u003c/strong\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://pub.dartlang.org/packages/flutter_hooks_test\"\u003e\n      \u003cimg src=\"https://img.shields.io/pub/v/flutter_hooks_test.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pub.dev/packages/flutter_lints\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/style-flutter__lints-40c4ff.svg\" alt=\"flutter_lints\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n## The first thing\n\nThis package is heavily inspired by [react-hooks-testing-library](https://github.com/testing-library/react-hooks-testing-library), and its core concepts are based on it.\n\n## The problem\n\nYou're writing a custom hook and you want to test it, but as soon as you call it you see\nthe following error:\n\n\u003e Bad state: This hook is called outside of a hook context.\n\nYou don't really want to write a widget solely for testing this hook and have to work out how you\nwere going to trigger all the various ways the hook can be updated, especially given the\ncomplexities of how you've wired the whole thing together.\n\n## The solution\n\nThe `Flutter Hooks Testing Library` allows you to create a simple test harness for Flutter hooks that\nhandles running them within the body of a widget, as well as providing various useful\nutility functions for updating the inputs and retrieving the outputs of your custom hook.\nThis library aims to provide a testing experience as close as possible to natively using your hook\nfrom within a real widget.\n\nUsing this library, you do not have to concern yourself with how to construct, render or interact\nwith the Flutter widget in order to test your hook. You can just use the hook directly and assert\nthe results.\n\n## When to use this library\n\n1. You're writing a library with one or more custom hooks that are not directly tied to a widget\n2. You have a complex hook that is difficult to test through widget interactions\n\n## When not to use this library\n\n1. Your hook is defined alongside a widget and is only used there\n2. Your hook is easy to test by just testing the widgets using it\n\n## Installation\n\n```yaml\ndev_dependencies:\n  flutter_hooks_test: ^2.0.0\n```\n\n## Example\n\n### `use_update.dart`\n\n```dart\nVoidCallback useUpdate() {\n  final attempt = useState(0);\n  return () =\u003e attempt.value++;\n}\n```\n\n### `use_update_test.dart`\n\n**Not using**\n\n```dart\ntestWidgets('should rebuild widget each time returned function is called', (tester) async {\n  // Before\n  const key = Key('button');\n  var buildCount = 0;\n\n  // called count is 1\n  await tester.pumpWidget(HookBuilder(builder: (context) {\n    final update = useUpdate();\n    buildCount++;\n    return GestureDetector(\n      key: key,\n      onTap: () =\u003e update(),\n    );\n  }));\n  // called count is 2\n  await tester.tap(find.byKey(key));\n  await tester.pumpAndSettle(const Duration(milliseconds: 1));\n  expect(buildCount, 2);\n});\n```\n\n**Using**\n\n```dart\ntestWidgets('should rebuild widget each time returned function is called', (tester) async {\n  // After\n  var buildCount = 0;\n  final result = await buildHook(\n    () {\n      buildCount++;\n      return useUpdate();\n    },\n    wrapper: (child) =\u003e Container(child: child),\n  );\n\n  expect(buildCount, 1);\n  final update = result.current;\n  await act(() =\u003e update());\n  expect(buildCount, 2);\n});\n```\n\n## Issues\n\nPlease file [Flutter Hooks Testing Library](https://github.com/wasabeef/flutter_hooks_test) specific issues, bugs, or feature requests in our [issue tracker](https://github.com/wasabeef/flutter_hooks_test/issues/new).\n\nPlugin issues that are not specific to [Flutter Hooks Testing Library](https://github.com/wasabeef/flutter_hooks_test) can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).\n\n## Contributing\n\nIf you wish to contribute a change to this project,\nplease review our [contribution guide](https://github.com/wasabeef/flutter_hooks_test/blob/main/CONTRIBUTING.md)\nand open a [pull request](https://github.com/wasabeef/flutter_hooks_test/pulls).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasabeef%2Fflutter_hooks_test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasabeef%2Fflutter_hooks_test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasabeef%2Fflutter_hooks_test/lists"}