Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Affordances for asserting on js console output #785

Open
1 task done
axelson opened this issue Jul 25, 2024 · 2 comments
Open
1 task done

Feature request: Affordances for asserting on js console output #785

axelson opened this issue Jul 25, 2024 · 2 comments

Comments

@axelson
Copy link

axelson commented Jul 25, 2024

Elixir and Erlang/OTP versions

Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.16.2 (compiled with Erlang/OTP 2

Operating system

macOS and Ubuntu

Browser

N/A or all

Driver

ChromeDriver

Correct Configuration

  • I confirm that I have Wallaby configured correctly.

Current behavior

I'd like to be able to easily assert on the js console output in my tests. Ideally I'd be able to assert that a specific console log was output for a given step of the test.

This is kind of possible right now with CaptureIO.capture_io but there's some drawbacks currently:

  • With js_logger set to the default CaptureIO.capture_io does capture the console output, but the console output is still printed to the terminal window that mix test is running in which makes it hard to read the test output
  • Most of the time I don't care about the console output so I'd like to be able to configure the console logging per-test so I don't need to wrap everything with CaptureIO
  • Adding a CaptureIO assertion for an individual step requires a helper function which breaks the flow of a test significantly, e.g. something like:
    |> assert_io(
      fn ->
        session
        |> visit(~p"/maps/#{team}/members")
      end,
      "members page visited"
    )

the helper is small:

  defp assert_io(session, fun, expected) when is_function(fun, 0) do
    js_io = CaptureIO.capture_io(fun)

    assert js_io =~ expected
  end

Although it might be possible to workaround that with a macro (but that might feel a bit too magical)

Expected behavior

I'd like it to be easier to assert on js console output and have that documented within the library

Test Code & HTML

N/A

Demonstration Project

No response

@mhanberg
Copy link
Member

Seems like a reasonable request and enhancement.

Another potential API is to make it so you could do something like

session
|> click(@button)
|> assert_console(~r/success/)

where assert_console has the same "waiting" functionality that some of the other assertions have, could also have like count: 2 etc options

@axelson
Copy link
Author

axelson commented Jul 25, 2024

Yeah that would be a great UX 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants