Add custom QUnit assertions to your ember-cli test suite
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
blueprints/assertion
config
test-support
tests
.editorconfig
.ember-cli
.eslintignore
.eslintrc.js
.gitignore
.npmignore
.travis.yml
.watchmanconfig
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
ember-cli-build.js
index.js
package-lock.json
package.json
testem.js

README.md

ember-cli-custom-assertions # Build Status

ember-cli-custom-assertions is built and maintained by DockYard, contact us for expert Ember.js consulting.

About

Add custom assertions to your Ember test suite.

Installing

ember install ember-cli-custom-assertions

Looking for help?

If it is a bug please open an issue on GitHub.

Usage

Add new assertions to test/assertions. Then use on the assert object in your test suite.

For example:

// tests/assertions/contains.js
export default function(context, element, text, message) {
  message = message || `${element} should contain "${text}"`;
  let actual = context.$(element).text();
  let expected = text;
  let result = !!actual.match(new RegExp(expected));

  this.pushResult({ result, actual, expected, message });
}

// tests/acceptance/foo-test.js
test('foo is bar', function(assert) {
  visit('/');

  andThen(function() {
    assert.contains('.foo', 'Foo Bar');
  });
});

Note: hyphenated file names like tests/assertions/double-trouble.js will be camelized: assert.doubleTrouble

Blueprint

You can generate a new assertion by using the assertion blueprint:

ember g assertion double-trouble

Assertion

A context is always injected as the first argument. You don't need to pass a context when calling the assertion, only when injecting the insertions into your app.

// good
assert.contains('.foo', 'Foo bar');

// bad
assert.contains(app, '.foo', 'Foo bar');

Setup

You must inject the assertions and pass the context along.

For example, with acceptance tests you can inject in beforeEach and cleanup in afterEach:

// ...
import { assertionInjector, assertionCleanup } from '../assertions';

module('Acceptance | foo', {
  beforeEach: function() {
    var application = startApp();
    assertionInjector(application);
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
    assertionCleanup(application);
  }
});

The import path should point at your tests folder. Alternatively, you could use an absolute path:

import { assertionInjector, assertionCleanup } from '<your app name>/tests/assertions';

Authors

We are very thankful for the many contributors

Versioning

This library follows Semantic Versioning

Want to help?

Please do! We are always looking to improve this library. Please see our Contribution Guidelines on how to properly submit issues and pull requests.

Legal

DockYard, Inc © 2015

@dockyard

Licensed under the MIT license