npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-qunit-custom-assertions

v2.0.1

Published

Library of QUnit custom assertions in Ember.

Downloads

2,346

Readme

ember-qunit-custom-assertions

npm npm github

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:

expect({}).to.be.empty;
expect([]).to.be.empty;

Similar results can be achieved using assert.notOk in QUnit too, but you would have to do something like this:

assert.notOk(Object.keys({}).length);
assert.notOk(Array.from([]).length);

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.empty({});
assert.empty([]);

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
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import setupCustomAssertions from 'ember-qunit-custom-assertions/test-support';

setApplication(Application.create(config.APP));

start();
setupCustomAssertions(config.modulePrefix);

// tests/unit/foo-test.js
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

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

  test('can use custom assertions', function(assert) {
    assert.includes('foo bar', 'bar');
  });
});

Assertions

assert.includes

Works on strings, arrays and objects.

params

  • actual [string/array/object]

  • expected [string/number]

  • message @optional

examples

assert.includes([1, 2, 3], 2, 'Array contains the specified element');
assert.includes([{x: 1}, {y: 2}, {z: 3}], {x: 1}, 'Array includes object');
assert.includes('foo bar', 'bar', 'String contains sub string');
assert.includes({ foo: "bar" }, 'foo', 'Object contains key');
assert.includes({ a: 1, b: 2, c: 3 }, { a: 1 }, 'Specified object is present in target object');

assert.notIncludes

Works on strings, arrays and objects.

params

  • actual [string/array/object]

  • expected [string/number]

  • message @optional

examples

assert.notIncludes([1, 2, 3], 2, 'Array does not contain the specified element');
assert.notIncludes([{x: 1}, {y: 2}, {z: 3}], {a: 15}, 'Array does not include object');
assert.notIncludes('foo bar', 'dog', 'String does not contain sub string');
assert.notIncludes({ foo: "bar" }, 'cat', 'Object does not contain the specified key');
assert.includes({ a: 1, b: 2, c: 3 }, { z: 4 }, 'Specified object is not present in target object');

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.deepIncludes([1,2,3], [1,2], 'Array includes elements');
assert.deepIncludes("Developed by Freshworks", ["Fresh","by"], 'String includes words');
assert.deepIncludes({x:1, y:2}, ['x', 'y'], 'Object has keys');

assert.notDeepIncludes

Works on strings, arrays and objects.

params

  • actual [string/array/object]

  • expected [array of string/number]

  • message @optional

examples

assert.notDeepIncludes([1,2,3], [4,5]);
assert.notDeepIncludes("Developed by Freshworks", ["Shibu","Lijack"]);
assert.notDeepIncludes({x:1, y:2}, ['a', 'b']);

assert.empty

Checks if a string, array or object is empty.

params

  • actual [string/array/object]

  • message @optional

example

assert.empty([], 'Empty array');
assert.empty({}, 'Empty array');
assert.empty('', 'Empty array');

assert.notEmpty

Checks if a string, array or object is not empty.

params

  • actual [string/array/object]

  • message @optional

example

assert.notEmpty([]);  // fails
assert.notEmpty([1, 2]);  // passes
assert.notEmpty({ foo: "bar" }, 'Not an empty object');
assert.notEmpty('foo', 'Not an empty string');

assert.length

Checks if the target’s length is equal to the given number.

params

  • actual _[string/array]

  • expected [number]

  • message @optional

example

assert.length('foo', 3);
assert.length(['foo', 'bar'], 2);

assert.lt

Checks if a number is lesser than expected.

params

  • actual [number]

  • expected [number]

  • message @optional

example

assert.lt(1, 4);

assert.lte

Checks if a number is lesser than or equal to expected.

params

  • actual [number]

  • expected [number]

  • message @optional

example

assert.lte(1, 4);
assert.lte(1, 1); // both pass

assert.gt

Checks if a number is greater than expected.

params

  • actual [number]

  • expected [number]

  • message @optional

example

assert.gt(15, 5);

assert.gte

Checks if a number is greater than or equal to expected.

params

  • actual [number]

  • expected [number]

  • message @optional

example

assert.gte(15, 5);
assert.gte(15, 15);

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.instanceOf(Array, []);
assert.instanceOf(Object, {});

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.