Socket
Socket
Sign inDemoInstall

ember-cli-custom-assertions

Package Overview
Dependencies
292
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ember-cli-custom-assertions

Easily add custom assertions to your Ember test suite


Version published
Weekly downloads
1.9K
increased by15.46%
Maintainers
4
Install size
28.7 MB
Created
Weekly downloads
 

Readme

Source

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.

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

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

Setup

You must inject the assertions to use them in tests.

New testing API
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import setupCustomAssertions from 'ember-cli-custom-assertions/test-support';

module('default setup', function(hooks) {
  setupTest(hooks);
  setupCustomAssertions(hooks);

  test('can inject custom assertions', function(assert) {
    assert.contains('.foo', 'Foo bar');
  });
});
Old testing API
// ...
import { assertionInjector, assertionCleanup } from 'ember-cli-custom-assertions/test-support';

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

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

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.

DockYard, Inc © 2015

@dockyard

Licensed under the MIT license

Keywords

FAQs

Last updated on 25 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc