From 2d67c73ac521e7284260b23681576b2a8650a772 Mon Sep 17 00:00:00 2001 From: Yelaman Yelmuratov Date: Sun, 12 May 2024 01:37:37 +0500 Subject: [PATCH] . d updated README.md file: added snippets for example with model --- CHANGELOG.md | 5 +- README.md | 79 +++++-------------- .../verify_as_json_test.approved.txt | 12 +-- .../verify_as_json/verify_as_json_test.dart | 25 +++++- 4 files changed, 51 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e81e8e..05bf40b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 0.4.1 -- Autopublish with new tags. +- Autopublish to pub.dev if the version in pubspec.yaml has been changed by auto adding a new tag to the repositories. +- Codecov added to github actions. Codecov badge, graph was added to README.md. +- Added mdsnippets to github actions. And example snippets added to README.md. +- Added `ApprovalTests.Dart.StarterProject'. You can find it in the README.md file. ## 0.3.9 diff --git a/README.md b/README.md index 6288707..43ab6e7 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,21 @@ dependencies: approval_tests: ^0.4.1 ``` +## 👀 Getting Started + +The best way to get started is to download and open the starter project: +* [Approvaltests.Dart.StarterProject](https://github.com/approvals/Approvaltests.Dart.StarterProject) + +This is a standard project that can be imported into any editor or IDE and also includes CI with GitHub Actions. + +It comes ready with: + +- A suitable `.gitignore` to exclude approval artifacts +- A ready linter with all rules in place +- A GitHub action to build and run tests +- A GitHub build status ToBadge + + ## 📚 How to use ### Approving Results @@ -153,68 +168,12 @@ And the `verify_methods` folder has small examples of using different `ApprovalT ### JSON example -```dart -import 'package:approval_tests/approval_dart.dart'; -import 'package:test/test.dart'; +snippet: same_verify_as_json_test_with_model -void main() { - test('Verify JSON output of an object', () { - var item = Item( - id: 1, - name: "Widget", - anotherItem: AnotherItem(id: 1, name: "AnotherWidget"), - subItem: SubItem( - id: 1, - name: "SubWidget", - anotherItems: [ - AnotherItem(id: 1, name: "AnotherWidget1"), - AnotherItem(id: 2, name: "AnotherWidget2"), - ], - ), - ); - - ApprovalTests.verifyAsJson( - item, - ); - }); -} - -/// Item class for testing -class Item { - final int id; - final String name; - final SubItem subItem; - final AnotherItem anotherItem; - - Item({ - required this.id, - required this.name, - required this.subItem, - required this.anotherItem, - }); -} - -/// Sub item class for testing -class SubItem { - final int id; - final String name; - final List anotherItems; - - SubItem({ - required this.id, - required this.name, - required this.anotherItems, - }); -} - -/// Another item class for testing -class AnotherItem { - final int id; - final String name; +this will result in the following file +`verify_as_json_test.approved.txt` - AnotherItem({required this.id, required this.name}); -} -``` +snippet: verify_as_json_test.approved.txt Passed test example diff --git a/example/verify_methods/verify_as_json/verify_as_json_test.approved.txt b/example/verify_methods/verify_as_json/verify_as_json_test.approved.txt index ee0c34d..7be2b3a 100644 --- a/example/verify_methods/verify_as_json/verify_as_json_test.approved.txt +++ b/example/verify_methods/verify_as_json/verify_as_json_test.approved.txt @@ -1,24 +1,24 @@ { - "item": { + "jsonItem": { "id": 1, - "name": "Widget", + "name": "JsonItem", "subItem": { "id": 1, - "name": "SubWidget", + "name": "SubItem", "anotherItems": [ { "id": 1, - "name": "AnotherWidget1" + "name": "AnotherItem 1" }, { "id": 2, - "name": "AnotherWidget2" + "name": "AnotherItem 2" } ] }, "anotherItem": { "id": 1, - "name": "AnotherWidget" + "name": "AnotherItem" } } } \ No newline at end of file diff --git a/example/verify_methods/verify_as_json/verify_as_json_test.dart b/example/verify_methods/verify_as_json/verify_as_json_test.dart index e0c7a16..76e3a66 100644 --- a/example/verify_methods/verify_as_json/verify_as_json_test.dart +++ b/example/verify_methods/verify_as_json/verify_as_json_test.dart @@ -1,13 +1,32 @@ import 'package:approval_tests/approval_tests.dart'; import 'package:test/test.dart'; -import '../../../test/approval_test.dart'; +import '../../../test/models/item.dart'; +// begin-snippet: same_verify_as_json_test_with_model void main() { + const jsonItem = JsonItem( + id: 1, + name: "JsonItem", + anotherItem: AnotherItem(id: 1, name: "AnotherItem"), + subItem: SubItem( + id: 1, + name: "SubItem", + anotherItems: [ + AnotherItem(id: 1, name: "AnotherItem 1"), + AnotherItem(id: 2, name: "AnotherItem 2"), + ], + ), + ); + test('Verify JSON output of an object', () { Approvals.verifyAsJson( - ApprovalTestHelper.jsonItem, - options: const Options(deleteReceivedFile: true), + jsonItem, + options: const Options( + deleteReceivedFile: true, // Automatically delete the received file after the test. + approveResult: true, // Approve the result automatically. You can remove this property after the approved file is created. + ), ); }); } +// end-snippet