Coder Social home page Coder Social logo

twinehealth / chai-datetime Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mguterl/chai-datetime

0.0 14.0 0.0 130 KB

Matchers for chai to help with common date equality assertions against JavaScript Date objects.

License: MIT License

JavaScript 100.00%

chai-datetime's Introduction

chai-datetime

Matchers for chai to help with common date comparison assertions against JavaScript Date objects.

Build Status

Why?

Comparing date objects in JavaScript is not based on value, which requires you to call getTime() to ensure the values match. These matchers remove the need to do that. Additionally when comparing getTime() values with the standard chai equality matcher you don't get very readable output because you're comparing epoch seconds.

Better Error Messages

Comparing date values for equality with getTime() gives unreadable error messages:

AssertionError: expected 1369944360000 to equal 1369944300000

Use chai-datetime to get something easier to read:

AssertionError: expected Thu May 30 2013 16:06:00 GMT-0400 (EDT) to equal Thu May 30 2013 16:05:00 GMT-0400 (EDT)

Usage

Browser

<script src="chai.js"></script>
<script src="chai-datetime.js"></script>

Server

var chai = require('chai');
chai.use(require('chai-datetime'));

Assertions

There are a collection of assertions that work on times and dates. Any assertion that specifies date in the name only compares the date portion of the Date object.

  • equalTime
  • beforeTime
  • afterTime
  • equalDate
  • beforeDate
  • afterDate

All assertions are defined for both the BDD and TDD syntaxes.

var d1 = new Date(2013, 4, 30, 16, 5),
    d2 = new Date(2013, 4, 30, 17);

d1.should.equalDate.d2
expect(d1).to.equalDate(d2)
assert.equalDate(d1, d2)

Thanks

Thanks to @mitchlloyd for pairing with me on this to help get me started. Thanks to @rockwood for putting up with my continuous trolling.

Thanks to the chai-fuzzy module for giving me an idea for how to structure and test a chai plugin.

chai-datetime's People

Contributors

mguterl avatar sgilroy avatar

Watchers

Bradley Harris avatar Eugene S avatar Bill Amidei avatar  avatar James Cloos avatar Nathaniel Waisbrot avatar Vitali Kukharchyk avatar Paul Wisner avatar  avatar TwineBot avatar Piyush Ramuka avatar  avatar  avatar Wai Cheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.