Can Wallaby Test JavaScript Vars?

I am working on a feature for a Phoenix app that adds Google Tag Manager variables under certain conditions. While unit testing the related Elixir modules is easy, I’m not sure how to actually test the “frontend” or javascript portion.

Id like to have a feature test that asserts:

  • yes this javascript variable was set and its value is foo
  • yes this javascript variable was set and its value is bar
  • yes this javascript variable was not set at all

Right now Im leaning towards either:

  • get a javascript testing framework
  • view page source of the Wallaby session, and view the contents of a script tag

Is there any way I can get the JS vars of the current window/session, and view their values (with Wallaby)?

You can use the execute_script function on the browser module and check JS values that way.

1 Like

Thanks! I also found a good example from a Wallaby PR that shows how to get the value by using the callback function (from execute_script/4).