Socket
Socket
Sign inDemoInstall

ember-cli-custom-assertions-collection

Package Overview
Dependencies
186
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ember-cli-custom-assertions-collection

An ever growing library of assertions for QUnit in Ember.


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

[0.2.3] - 2015-09-23

Documentation

  • Moar badges!
  • Filled in the description field in package.json.

Readme

Source

Travis npm npm Ember Observer Score

ember-cli-custom-assertions-collection

Turns out it's impossible to effectively use Chai in QUnit. Chai throws exceptions on failed Chai assertions, which are tracked by QUnit, though with a poor message. But Chai is unable to report successful assertions to QUnit. If you compose a QUnit test entirely from Chai assertions, QUnit will fail due to no assertions.

This is really unfortunate because Chai has a decent assertions library, and QUnit's library is very basic and often not enough.

This Ember addon aims to provide missing assertions and many more.

Assertions themselves are properly unit-tested.

Work in progress

This addon is WIP and is being populated with assertions as they are needed.

Feel free to join. Find yourself doing clumsy stuff in tests? PR a custom assertion!

Dependencies

This addon depends on the following addons:

And plain npm packages:

If you find it not working due to something of the above missing, try installing that into your app. And file an issue here!

Usage

  1. Install ember-cli-custom-assertions and wrap your head around it.
  2. Install this addon: ember cli install ember-cli-custom-assertions-collection.
  3. If a test needs a custom assertion, configure it to use ember-cli-custom-assertions.
  4. Use any assertion from this collection, e. g. assert.isFalse(foo, 'foo should be false').

The assertions

isFalse( obj [, message] )

Checks if obj is exactly false.

assert.isFalse( false )   // pass
assert.isFalse( 1 === 2 ) // pass
assert.isFalse( null )    // fail
arraysSameMembers( arr1, arr2 [, message] )

Checks if both arrays have identical content, in any order. Members are compared via ===.

assert.arraysSameMembers( ['foo', 'bar'], ['bar', 'foo'] ) // pass
assert.arraysSameMembers( ['foo', 'bar'], ['bar', 'baz'] ) // fail
assert.arraysSameMembers( ['foo', 'bar'], ['bar']        ) // fail
arraysSameMembersOrdered( arr1, arr2 [, message] )

Checks if both arrays identical content, in identical order. Members are compared via ===.

assert.arraysSameMembersOrdered( ['foo', 'bar'], ['foo', 'bar'] ) // pass
assert.arraysSameMembersOrdered( ['foo', 'bar'], ['bar', 'foo'] ) // fail
assert.arraysSameMembersOrdered( ['foo', 'bar'], ['bar', 'baz'] ) // fail
assert.arraysSameMembersOrdered( ['foo', 'bar'], ['bar']        ) // fail
numbersAlmostEqual( number1, number2 [, precision = 6] [, message] )

You know how 1 - 0.9 === 0.1 is false in JS? That's because in JS float-point operations aren't precise.

Use this to compare them loosely:

assert.numbersAlmostEqual( 1 - 0.9, 1                     ) // pass
assert.numbersAlmostEqual( 1 - 1/3, 2/3                   ) // pass
assert.numbersAlmostEqual( 1,       0.00001               ) // fail
assert.numbersAlmostEqual( 1,       0.00001, precision: 4 ) // pass

This assertion uses a method suggested by MDN. Not sure whether it'll work correctly every time.

Plans

If this thing catches up, we could document it with YUIDOC.

All suggestion are welcome in issues and in Ember Slack community.

Oh, and don't forget to star the addon on Github! :beers"

Credit

Created in Firecracker.

Keywords

FAQs

Last updated on 23 Sep 2015

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