methods.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var Pikaday = require('../'),
  2. expect = require('expect.js');
  3. describe('Pikaday public method', function ()
  4. {
  5. 'use strict';
  6. describe('#toString()', function ()
  7. {
  8. it('should return empty string when date not set', function ()
  9. {
  10. var pikaday = new Pikaday();
  11. expect(pikaday.toString()).to.be.empty;
  12. });
  13. it('should return date string, formatted by moment, when date is set', function() {
  14. var date = new Date(2014, 3, 25),
  15. pikaday = new Pikaday({
  16. format: 'DD-MM-YY'
  17. });
  18. pikaday.setDate(date);
  19. expect(pikaday.toString()).to.eql('25-04-14');
  20. });
  21. });
  22. describe('When specifying minDate option in Constructor', function () {
  23. it('Should remove the time portion (flattening to midnight)', function () {
  24. var date = new Date(2015, 1, 17, 22, 10, 5),
  25. expected = new Date(2015, 1, 17, 0, 0, 0),
  26. pikaday = new Pikaday({ minDate: date });
  27. expect(pikaday._o.minDate).to.eql(expected);
  28. });
  29. });
  30. describe('#setMinDate()', function () {
  31. it('should flatten date to midnight ignoring time portion (consistent with minDate option in ctor)', function () {
  32. var date = new Date(2015, 1, 17, 22, 10, 5),
  33. expected = new Date(2015, 1, 17, 0, 0, 0),
  34. pikaday = new Pikaday();
  35. pikaday.setMinDate(date);
  36. expect(pikaday._o.minDate).to.eql(expected);
  37. });
  38. });
  39. });