1

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?

4

1 回答 1

3

assert对象是一个单例实例,您可以使用QUnit.assert. 所以以下应该工作

import QUnit from 'qunit';

QUnit.assert.controlDisabled = function(selector, message) {
  return this.ok(findWithAssert(selector).attr('disabled'), message);
};
于 2015-02-22T03:34:49.940 回答