When trying to call the press() method, I always get
InvalidArgumentException: Unreachable field ""
at that line.
According to the docs:
"Press" a button with the given text or name.
My method:
press('Create') and my button is
<button class="btn btn-lg btn-primary" type="submit" name="submit">Create</button> I have also tried to use the name with the same result.
I have also tried submitForm('Create') which works, but then seeInDatabase('employees', ['email' => 'john@email.com']) always fails.
Unable to find row in database table [employees] that matched attributes [{"email":"john@email.com"}].
Here is my full method
public function testExample() { $this->actingAs(\App\Employee::where('username', 'grant')->first()) ->visit('/employees/create') ->type('john', 'username') ->type('1234', 'password') ->type('john@email.com', 'email') ->submitForm('Create') ->seeInDatabase('employees', ['email' => 'john@email.com']) ->see('Employee Directory'); } 2 Answers
Answers 1
I'm not sure what the exact cause of your problem is but it could be a couple of things. I would have commented but I don't have enough reputation yet.
Firstly, have you run your plain html trough a validator? If it gives you any syntax errors try to fix them and run the unit test again. (You can try this one https://validator.w3.org/, just copy and paste your html)
Another cause may be that you have some javascript that modifies your DOM and Laravel testing can't handle that.
And lastly, you can try to set the 'value' attribute of your <button> to "Create"
<button class="btn btn-lg btn-primary" type="submit" name="submit" value="Create">Create</button> Or change the <button> to an <input> with type attribute "submit" and value to "Create"
<input type="submit" class="btn btn-lg btn-primary" name="submit" value="Create" /> Answers 2
Try this:
<button class="btn btn-lg btn-primary" type="submit" name="Create">Create</button>
0 comments:
Post a Comment