kylemellander / ember-test-with-data

Consistent ember acceptance and integration tests with data attributes.
MIT License
15 stars 2 forks source link

ember-test-with-data

Code Climate

Introduction

ember-test-with-data keeps integration and acceptance testing consistent by using tags set specifically in HTML5 data attributes.

Why should I use data attributes?

HTML markup and css classes are often sufficient for selecting DOM elements, but that is not the purpose of why they are inserted into your code. HTML provides the structure for your page and css gives your page styling. To use them for testing, we give them a secondary purpose, which can sometimes create unneed complexity.

By creating data-test attributes on elements, we can specifically select DOM elements with that attribute being a sole purpose of helping you test.

What does this do differently than others?

There are 2 data attribute addons out there.

So why use ember-test-with-data?

Features

Installation

ember install ember-test-with-data

That's it! It should work out of the box, but there are some settings you can change.

Configuration

You can set your preferences for hidden environments in ember-test-with-data in the ember-cli-build.js file in your ember-cli app. Example:

// ember-cli-build.js
module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    'ember-test-with-data': {
      hidden: EmberApp.env() === 'production'
    }
  })

  return app.toTree()
}

Because the other options are run after build, then they are set in the apps config/environment.js file. Example:

// config/environment.js
module.exports = function(environment) {
  var ENV = {
    /*
    * Your settings in here
    */
  };

  ENV['ember-test-with-data'] = {
    dataTestSuffix: 'id',                          // default null
    autoTag: true                                  // default true
  }
}
Settings

ember-cli-build options

config/environment options

Acceptance Test Helper

To help you simplify your testing, an acceptance test helper is provided. To use it in your acceptance tests, simply add the following line to the top of your start-app.js helper.

// tests/helpers/start-app.js

import Ember from 'ember';
import './ember-test-with-data/find-with-data';

...

Now in your app you can use findWithData('VALUE_OF_DATA_TEST_ATTRIBUTE') and it will find the element you are needing to test.

Future features