Huafu
Huafu

Reputation: 2465

ember-cli extend assert with custom assertion helpers

In the latest ember-cli, in the unit tests the test function expect as last parameter a function which would have the assert object as first parameter.

I was wondering how can I extend this object to add my own custom assertion helpers?

For example I want to add a controlDisabled helper that would return true if the control is disabled, and false otherwise. So somewhere (but not in each test files) I want to extend that assert object given as paramter like so:

assert.controlDisabled = function(selector, message) {
  return this.ok(findWithAssert(selector).attr('disabled'), message);
};

Where should I define this?

Upvotes: 1

Views: 339

Answers (1)

Marcio Junior
Marcio Junior

Reputation: 19128

The assert object is a singleton instance which you can gain access with QUnit.assert. So the following should work

import QUnit from 'qunit';

QUnit.assert.controlDisabled = function(selector, message) {
  return this.ok(findWithAssert(selector).attr('disabled'), message);
};

Upvotes: 3

Related Questions