[L5.1] Testing with Select2 jQuery plugin

Posted 3 years ago by olimorris

Hi All,

I've just switched over to the brilliant Select2 plugin and I'm currently using it to allow users to search or create new tags in a form. It works perfectly when I manually test it however I'm in the middle of writing a test using Laravel 5.1 and cannot seem to mimic the user input of writing into the Select2 field.

My HTML is:

<select class="tags-field" name="tags[]" data-tags="true" data-placeholder="SKILLS" multiple="multiple"></select>

and my Test code is:

/** @test */
public function it_successfully_posts_a_job()
{
    $this->click('Post A Job');
    $this->seePageIs('/jobs/create');

    // and I fill out the Post A Job Form
    $this->submitForm('Post Job', [
        'title' => 'Some title',
        'description' => 'Some description',
        'tags' => 'Tag1,Tag2,Tag3',
    ]);
}

the error message I get is:

1) PostAJobTest::it_successfully_posts_a_job
InvalidArgumentException: Input "tags" cannot take "Tag1,Tag2,Tag3" as a value (possible values: ).

/home/vagrant/Code/Dev/vendor/symfony/dom-crawler/Field/ChoiceFormField.php:140
/home/vagrant/Code/Dev/vendor/symfony/dom-crawler/FormFieldRegistry.php:128
/home/vagrant/Code/Dev/vendor/symfony/dom-crawler/Form.php:76
/home/vagrant/Code/Dev/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:681
/home/vagrant/Code/Dev/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php:661
/home/vagrant/Code/Dev/tests/HelpersTrait.php:116
/home/vagrant/Code/Dev/tests/Integration/PostAJobTest.php:14

I wondered whether any of you had come across this problem before?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.