{"id":20664034,"url":"https://github.com/flutterando/value_listenable_test","last_synced_at":"2025-09-03T02:09:09.342Z","repository":{"id":43693534,"uuid":"444465041","full_name":"Flutterando/value_listenable_test","owner":"Flutterando","description":"Assists in testing ValueListenable objects (ex: ValueNotifier).","archived":false,"fork":false,"pushed_at":"2023-05-30T03:12:40.000Z","size":5,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-19T18:54:40.688Z","etag":null,"topics":["dart"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/value_listenable_test","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Flutterando.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-04T15:14:23.000Z","updated_at":"2025-03-26T20:54:45.000Z","dependencies_parsed_at":"2024-11-16T21:17:41.584Z","dependency_job_id":null,"html_url":"https://github.com/Flutterando/value_listenable_test","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"366a9ec7f2d82025d14e8303e746a0957446d41c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Flutterando/value_listenable_test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_listenable_test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_listenable_test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_listenable_test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_listenable_test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flutterando","download_url":"https://codeload.github.com/Flutterando/value_listenable_test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_listenable_test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273377153,"owners_count":25094528,"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","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"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"],"created_at":"2024-11-16T19:21:47.220Z","updated_at":"2025-09-03T02:09:09.332Z","avatar_url":"https://github.com/Flutterando.png","language":"Dart","readme":"# value_listenable_test\n\nAssists in testing **ValueListenable** objects (ex: **ValueNotifier**).\n\n## install\n\nAdded in your `pubspec.yaml` as **dev dependency**:\n\n```yaml\ndev_dependencies:\n  value_listenable_test: any\n```\n## Unit test with emitValues and valueListenableTest\n\nListen the emits of ValueListenable:\n\n```dart\n test('valueListenable Matcher', () {\n     final counter = ValueNotifier(0);\n     expect(counter, emitValues([2, 3, 5]));\n     counter.value = 2;\n     counter.value = 3;\n     counter.value = 5;\n   });\n```\n\nAlso, you can use the test abstraction called **valueListenableTest**:\n\n```dart\nvalueListenableTest\u003cCounter\u003e(\n  'Counter emits [1] when update method is called',\n  build: () =\u003e Counter(),\n  act: (notifier) =\u003e notifier.update(1),\n  expect: () =\u003e [1],\n);\n```\n## Mock\n\nIt's easy, just extend the `MockValueListenable`:\n\n```dart\nclass MockCounter extends MockValueListenable\u003cint\u003e {}\n```\n\nTo notify the listeners with a new value call the [callListeners] method.\n\n```dart\nfinal counter = MockCounter();\ncounter.addListener(() =\u003e print(counter.value)); // 50\nwhen(() =\u003e counter.value).thenReturn(50);\nprint(counter.value); // 50\ncounter.callListeners();\n```\n\n## Stub the value\n\nCreates a stub response for the `addListener` method on a `valueListenable`.\nThe `valueListenable` will have each `value` (in order) after the`input` is called.\nOptionally provide an `initialValue` to stub the `value` of the `valueListenable`,\nor also optionally provide a `delay` between the `values` change.\n\n```dart\n// Create a mock instance\nfinal counter = CounterMock();\n\n// Stub the value\nwhenListen(\n  counter,\n  input: counter.increment,\n  initialValue: 0,\n  values: [1, 2, 3],\n);\n\n// Assert that the initial value is correct.\nexpect(counter.value, 0);\n\n// Verifies values after to call increment\nvalueListenableTest\u003cCounter\u003e(\n  'value = [1, 2, 3] when increment is called',\n  build: () =\u003e counter,\n  act: (notifier) =\u003e notifier.increment(),\n  expect: () =\u003e [1, 2, 3],\n);\n```\n\n\u003e**Note:** When setting the **initialValue** the listeners are never called, then **emitValues**\n\u003eand **valueListenableTest** methods never must expect that.\n\nThat`s it!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterando%2Fvalue_listenable_test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflutterando%2Fvalue_listenable_test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterando%2Fvalue_listenable_test/lists"}