newbie360's avatar

possible to test frontend toggle dark mode behavior without install Dusk?

i have write some code to enable Tailwind Dark Mode

https://i.ibb.co/y5XwTWh/firefox-QEGbgv-ZLI2.gif

playground: https://laravelplayground.com/#/snippets/d1f6debb-bd78-440a-b4a0-42683d861c2a

when i click on the button:

  1. update the <html> attributes
  2. update localStorage value
  3. update the svg hidden class

but how to write a Test for 1~3 without install Dusk?

0 likes
4 replies
tisuchi's avatar

@newbie360 If I understand correctly, (although) it's a CSS behavior, it depends on JS (alternatively JS behavior).

I think it's not possible to test in PHPUnit.

2 likes
newbie360's avatar

@tisuchi It means we need install Google Chrome and add the laravel/dusk Composer dependency to the project ?

and run another command php artisan dusk for the test ?

that seems too much...

may be i change the question

we will Test a model can create, edit, delete

do we really need to Test such like frontend behavior? since it is not important and not affect database layer

2 likes
tisuchi's avatar
tisuchi
Best Answer
Level 70

@newbie360

It means we need install Google Chrome and add the laravel/dusk Composer dependency to the project ? and run another command php artisan dusk for the test ?

YES

we will Test a model can create, edit, delete

NO. It depends what exactly you want to test! If you want to test the CRUD operation in Laravel code, simply you can use PHP Unit test, because it's testing your code whether it's working as expected or not, nothing else.

Now, if you want to test the CRUD feature whether it's working perfectly in the browser surely you need to use front-end testing, e.g. dusk.

2 likes

Please or to participate in this conversation.