Http test redirecting to \ instead of login

Published 2 weeks ago by ddw147

Hi I am trying out testing in laravel5.6, but when try to test invalid login like below

public function testInvalidLogin()
    {
        $response = $this->post('/login',[ 'email'=>'[email protected]', 'password'=>'secret' ]);
        $response->assertStatus(302);
        $response->assertLocation('/login');
 }

but when i run this i got error

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/login'
+'http://localhost'

D:\project\larademo\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:198
D:\project\larademo\tests\Feature\ExampleTest.php:38

FAILURES!
Tests: 3, Assertions: 5, Failures: 1.

I have also use followingRedirects() but it is giving response code 200 and content of '/'

can you help me what is wrong here

NickVahalik

Well, if you are following the redirects then when you process the 302, the location will change accordingly.

What does the login controller look like? Sounds like it's doing exactly what it is supposed to do.

ddw147

Hi LoginController is default provided with laravel , no changes there

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