Ajvanho's avatar
Level 14

Feature test, expected ExactJson

How to get the expected form of json.

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"data":{"childrens":{"name":"Dr.","slug":"dr"},"name":"Prof.","slug":"prof"}}'
+'{"data":[{"childrens":[{"name":"Dr.","slug":"dr"}],"name":"Prof.","slug":"prof"}]}

$response->assertStatus(200)
            ->assertExactJson([

                "data" => [
                    "name" => $categories->name,
                    "slug" => $categories->slug,
                    "childrens" => [
                        "name" => $anotherCategory->name,
                        "slug" => $anotherCategory->slug,
                    ]
                ]

            ]);
0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60
->assertExactJson([
	"data" => [
		[
			"name" => $categories->name,
			"slug" => $categories->slug,
			"childrens" => [
				[
					"name" => $anotherCategory->name,
					"slug" => $anotherCategory->slug,
				]
			]
		]
	]
]);

try this

1 like

Please or to participate in this conversation.