ember-qunit-custom-assertions
QUnit has a very basic collection of assertions, especially when compared to something like chai.
Let's take an example. If you want to check if a string/array/object is empty, you would do something like this in chai:
tobeempty;tobeempty;
Similar results can be achieved using assert.notOk
in QUnit too, but you would have to do something like this:
assert;assert;
Wouldn't it be easier if there's a cleaner way to achieve the same results? Well, look no further, ember-qunit-custom-assertions
to the rescue.
assert;assert;
Compatibility
- Ember.js v2.18 or above
- Ember CLI v2.13 or above
- Node.js v8 or above
Installation
ember install ember-qunit-custom-assertions
Usage
You must call the setupCustomAssertions function in your test helper to use the custom assertions in your tests.
// tests/test-helper.js;;;;; ; ;; // tests/unit/foo-test.js;; module'default setup' { ; ;};
Assertions
assert.includes
Works on strings, arrays and objects.
params
-
actual
[string/array/object] -
expected
[string/number] -
message
@optional
examples
assert;assert;assert;assert;assert;
assert.notIncludes
Works on strings, arrays and objects.
params
-
actual
[string/array/object] -
expected
[string/number] -
message
@optional
examples
assert;assert;assert;assert;assert;
assert.deepIncludes
Checks if target has the expected elements/keys. Works on strings, arrays and objects.
params
-
actual
[string/array/object] -
expected
[array of string/number] -
message
@optional
examples
assert;assert;assert;
assert.notDeepIncludes
Works on strings, arrays and objects.
params
-
actual
[string/array/object] -
expected
[array of string/number] -
message
@optional
examples
assert;assert;assert;
assert.empty
Checks if a string, array or object is empty.
params
-
actual
[string/array/object] -
message
@optional
example
assert;assert;assert;
assert.notEmpty
Checks if a string, array or object is not empty.
params
-
actual
[string/array/object] -
message
@optional
example
assert; // failsassert; // passesassert;assert;
assert.length
Checks if the target’s length is equal to the given number.
params
-
actual
_[string/array] -
expected
[number] -
message
@optional
example
assertlength'foo' 3;assertlength'foo' 'bar' 2;
assert.lt
Checks if a number is lesser than expected.
params
-
actual
[number] -
expected
[number] -
message
@optional
example
assert;
assert.lte
Checks if a number is lesser than or equal to expected.
params
-
actual
[number] -
expected
[number] -
message
@optional
example
assert;assert; // both pass
assert.gt
Checks if a number is greater than expected.
params
-
actual
[number] -
expected
[number] -
message
@optional
example
assert;
assert.gte
Checks if a number is greater than or equal to expected.
params
-
actual
[number] -
expected
[number] -
message
@optional
example
assert;assert;
assert.instanceOf
Checks if the target is an instance of the expected type.
params
-
expected
[Array/Object/Date] -
target
[Array/Object/Date] -
message
@optional
example
assert;assert;
Contributing
See the Contributing guide for details.
License
This project is licensed under the MIT License.