我正在为表单编写一个小测试,我在运行phpunit时遇到错误。它会卡住,因为它无法在名为organisation
的下拉框中看到任何选项,该框由vuejs填充。有问题的下拉列表中填充了页面首次加载时加载的json值列表,并由表单中的第一个下拉列表进一步过滤,即academic_certificate
。
这是我的视图/刀片文件,包含下拉列表:
<select name="organisation" id="" class="form-control" {{-- required="required" --}} v-model="organisation">
<option value="">Select</option>
<option v-for="organisation in organisations | filterBy application_type in 'organisation_types'">
@{{ organisation.name }}
</option>
</select>
这是我的测试:
/** @test */
public function verified_user_can_create_academic_certificate_application()
{
$faker = Faker::create();
$user = factory(App\Models\User::class)->create();
$applicant = Role::where('name', 'applicant')->firstOrFail();
$user->roles()->attach($applicant->id);
$this->actingAs($user)
->visit('/applicant/application/create')
->select('academic_certificate', 'application_type')
->type($faker->firstNameMale, 'first_names')
->type($faker->lastName, 'last_name')
// fill out rest of form ...
/****************************************
here's where it gets an error!
****************************************/
->select('Some organisation', 'organisation')
->select('1', 'qualification')
->type('IT', 'speciality')
->type('2002', 'year_of_award')
->press('Submit')
->see('complete');
}
运行测试时:
$ vendor/bin/phpunit
PHPUnit 4.8.23 by Sebastian Bergmann and contributors.
E.FF
Time: 7.15 seconds, Memory: 37.00Mb
There was 1 error:
1) ApplicationTest::verified_user_can_create_academic_certificate_application
InvalidArgumentException: Input "organisation" cannot take "Some organisation" as a value (possible values: ,
{{ organisation.name }}
).
C:\wamp\www\attestation\vendor\symfony\dom-crawler\Field\ChoiceFormField.php:140
C:\wamp\www\attestation\vendor\symfony\dom-crawler\FormFieldRegistry.php:128
C:\wamp\www\attestation\vendor\symfony\dom-crawler\Form.php:77
C:\wamp\www\attestation\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:808
C:\wamp\www\attestation\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:788
C:\wamp\www\attestation\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:775
C:\wamp\www\attestation\tests\acceptance\applicant\ApplicationTest.php:55
任何帮助都会非常感激,我正试图掌握测试,并且不愿意被困在这里!谢谢。
修改
我意识到我错过了标记中的value属性:
<select name="organisation" id="" class="form-control" {{-- required="required" --}} v-model="organisation">
<option value="">Select</option>
<option
v-for="organisation in organisations | filterBy application_type in 'organisation_types'"
value="@{{ organisation.id }}"
>
@{{ organisation.name }}
</option>
</select>
我现在已添加,但同样的问题仍然存在。
答案 0 :(得分:0)
您的<option value="">Select</option>
代码行的开头为空。我有几乎相同的确切问题。给您的价值一个价值,它可能会解决它。