我对现场验证进行了一些测试。 如何断言响应错误消息? 这是我的简单测试
/** @test */
public function categoryRequiresName()
{
$response = $this->postGraphQL([
'query' => '
mutation CreateCategory($name: String!) {
createCategory(name: $name) {
name
}
}
',
'variables' => [
'name' => '',
],
]);
// how to assert Response message ?
// edited solution
$this->assertEquals("The name field is required.", $response->json("errors.0.extensions.validation.name.0"));
}
这是我在突变领域的规则
name: String @rules(apply: ["required"])
这是错误树