diff --git a/README.md b/README.md index 43ab6e7..a0f8e99 100644 --- a/README.md +++ b/README.md @@ -168,12 +168,71 @@ And the `verify_methods` folder has small examples of using different `ApprovalT ### JSON example -snippet: same_verify_as_json_test_with_model + + +```dart +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( + 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. + ), + ); + }); +} +``` +snippet source | anchor + this will result in the following file `verify_as_json_test.approved.txt` -snippet: verify_as_json_test.approved.txt + + +```txt +{ + "jsonItem": { + "id": 1, + "name": "JsonItem", + "subItem": { + "id": 1, + "name": "SubItem", + "anotherItems": [ + { + "id": 1, + "name": "AnotherItem 1" + }, + { + "id": 2, + "name": "AnotherItem 2" + } + ] + }, + "anotherItem": { + "id": 1, + "name": "AnotherItem" + } + } +} +``` +snippet source | anchor + Passed test example