Skip to content

Elixir library to help selecting the right elements in your tests.

License

Notifications You must be signed in to change notification settings

DefactoSoftware/test_selector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TestSelector

CircleCI Module Version Hex Docs Total Download License Last Updated

A set of Elixir helpers to set/get test selectors to/from elements in a Phoenix app (when Mix.env == :test). These selectors are hashed (scoped to the view module they are used in) for accurate selection and "leakage" prevention. See our Wiki for examples.

Why? Because we prefer reserving classes for styling, and id's have limitations because they have to be unique.

Dependencies

  • Floki v0.25.x and higher

Installation

def deps do
  [
    {:test_selector, "~> 0.3.3"}
  ]
end

Use TestSelector.HTML.Helpers to your web.ex.

  • In phoenix 1.2.0 at web/web.ex
  • In newer Phoenix versions lib/your_project/web/web.ex

Add somewhere along:

def view(opts \\ []) do
  quote do
    ...
    use Phoenix.HTML

    use TestSelector.HTML.Helpers
    ...
  end
end

Testing with Floki

In the tests import the TestSelector.Test.FlokiHelpers:

defmodule Project.Web.MyTest do
  ...

  import TestSelector.Test.FlokiHelpers
  ...
end

Tests

Run the tests:

mix test

Copyright and License

Copyright (c) 2017 Defacto

Released under the MIT License, which can be found in the repository in LICENSE.md.

About

Elixir library to help selecting the right elements in your tests.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published