Socket
Socket
Sign inDemoInstall

ember-cli-custom-assertions-collection

Package Overview
Dependencies
1
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
Maintainers
1
Created

Changelog

Source

[0.5.0] - 2015-09-29

Added

  • datesEqual

Documentation

  • Fixed Travis badge image URL.
  • Added code sample for 'smallerThan'.

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
    isFalse( obj [, message] )
    

    Checks if obj is exactly false.

    assert.isFalse( false )   // pass
    assert.isFalse( 1 === 2 ) // pass
    assert.isFalse( null )    // fail
    
  • arrayContains
    arrayContains( arr, value [, message])
    

    Checks if array contains value

    assert.arrayContains(['foo', 'bar'], 'bar')  // pass
    assert.arrayContains(['foo', 'bar'], 'quux') // fail
    
  • arraysSameMembers
    arraysSameMembers( arr1, arr2 [, message] )
    

    Checks if both arrays have identical content, in any order.

    Members are compared via ===, so it's safe to compare Ember models: will not crash due to circular references like propEqual does.

    assert.arraysSameMembers( ['foo', 'bar'], ['bar', 'foo'] ) // pass
    assert.arraysSameMembers( ['foo', 'bar'], ['bar', 'baz'] ) // fail
    assert.arraysSameMembers( ['foo', 'bar'], ['bar']        ) // fail
    
  • arraysSameMembersOrdered
    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
    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.

  • largerThan, largerThanOrEqual, smallerThan, smallerThanOrEqual
    largerThan(arg1, arg2 [, message])
    

    Compares the two arguments using >, >=, < and <= respectively.

    assert.smallerThan( 1, 2 ) // pass
    
  • datesEqual
    datesEqual(date1, date2 [, message])
    

    So dates are objects and two distinct objects aren't equal even if they represent identical dates.

    This assertion compares the two dates by converting them to unix timestamp integers and comparing those.

    assert.datesEqual( new Date('2015-01-01'), new Date('2015-01-01') ) // pass
    

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 29 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