2

I am writing tests for the search functionality in my laravel app. I want to mock the user behaviour so in my tests I have sth like

public function testSearchCanBeDone()
    {
        $this->visit('/')
             ->type('name', 'query')
             ->press('Search') //In my case press enter key
             ->seePageIs('/search?query=name')
             ->see('Results');
    }
}

My problem is at the ->press('Find') now that I don't have a search button. In my case after typing inside the search field one presses the enter key. How do I go about it. This is the code for my search form

<form method="GET" action="/search" role="search">
    <div class="input-field">
        <input name = "query" id="search" type="search" class="search" required>
            <label for="search">
                <i class="material-icons teal-text text-lighten-2">search</i>
            </label>
        <i class="material-icons">close</i>
    </div>
</form>

1 Answer 1

2

I think you crossed that fine line between UI testing and unit testing. One way around that is to call $this->get('/search', $params)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.