Skip to content

Commit

Permalink
Switch core tests to QUnit and es6 modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood authored and ichernev committed Mar 25, 2015
1 parent 78a53b8 commit 7ce3fa7
Show file tree
Hide file tree
Showing 38 changed files with 6,553 additions and 7,881 deletions.
692 changes: 323 additions & 369 deletions test/moment/add_subtract.js

Large diffs are not rendered by default.

1,815 changes: 849 additions & 966 deletions test/moment/create.js

Large diffs are not rendered by default.

50 changes: 18 additions & 32 deletions test/moment/days_in_month.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
var moment = require('../../moment');
import { module, test } from "../qunit";
import moment from "../../moment";
import each from "../helpers/each";

exports.daysInMonth = {
setUp : function (done) {
moment.createFromInputFallback = function () {
throw new Error('input not handled by moment');
};
done();
},
module('days in month');

'days in month' : function (test) {
test.expect(24);
var months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], i;
for (i = 0; i < 12; i++) {
test.equal(moment([2012, i]).daysInMonth(),
months[i],
moment([2012, i]).format('L') + ' should have ' + months[i] + ' days. (beginning of month ' + i + ')');
}
for (i = 0; i < 12; i++) {
test.equal(moment([2012, i, months[i]]).daysInMonth(),
months[i],
moment([2012, i, months[i]]).format('L') + ' should have ' + months[i] + ' days. (end of month ' + i + ')');
}
test.done();
},
test('days in month', function (assert) {
each([31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], function (days, i) {
var firstDay = moment([2012, i]);
var lastDay = moment([2012, i, days]);
assert.equal(firstDay.daysInMonth(), days, firstDay.format('L') + ' should have ' + days + ' days.');
assert.equal( lastDay.daysInMonth(), days, lastDay.format('L') + ' should have ' + days + ' days.');
});
});

'days in month leap years' : function (test) {
test.expect(4);
test.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days');
test.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days');
test.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days');
test.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days');
test.done();
}
};
test('days in month leap years', function (assert) {
assert.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days');
assert.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days');
assert.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days');
assert.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days');
});
445 changes: 199 additions & 246 deletions test/moment/diff.js

Large diffs are not rendered by default.

1,193 changes: 552 additions & 641 deletions test/moment/duration.js

Large diffs are not rendered by default.

101 changes: 45 additions & 56 deletions test/moment/duration_from_moments.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
var moment = require('../../moment');

exports.durationFromMoments = {
setUp: function (done) {
moment.createFromInputFallback = function () {
throw new Error('input not handled by moment');
};
done();
},

'pure year diff' : function (test) {
var m1 = moment('2012-01-01T00:00:00.000Z'),
m2 = moment('2013-01-01T00:00:00.000Z');

test.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference');
test.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference');
test.done();
},

'month and day diff' : function (test) {
var m1 = moment('2012-01-15T00:00:00.000Z'),
m2 = moment('2012-02-17T00:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

test.equal(d.get('days'), 2);
test.equal(d.get('months'), 1);
test.done();
},

'day diff, separate months' : function (test) {
var m1 = moment('2012-01-15T00:00:00.000Z'),
m2 = moment('2012-02-13T00:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

test.equal(d.as('days'), 29);
test.done();
},

'hour diff' : function (test) {
var m1 = moment('2012-01-15T17:00:00.000Z'),
m2 = moment('2012-01-16T03:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

test.equal(d.as('hours'), 10);
test.done();
},

'minute diff' : function (test) {
var m1 = moment('2012-01-15T17:45:00.000Z'),
m2 = moment('2012-01-16T03:15:00.000Z'),
d = moment.duration({from: m1, to: m2});

test.equal(d.as('hours'), 9.5);
test.done();
}
};
import { module, test } from "../qunit";
import moment from "../../moment";

module('duration from moments');

test('pure year diff', function (assert) {
var m1 = moment('2012-01-01T00:00:00.000Z'),
m2 = moment('2013-01-01T00:00:00.000Z');

assert.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference');
assert.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference');
});

test('month and day diff', function (assert) {
var m1 = moment('2012-01-15T00:00:00.000Z'),
m2 = moment('2012-02-17T00:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

assert.equal(d.get('days'), 2);
assert.equal(d.get('months'), 1);
});

test('day diff, separate months', function (assert) {
var m1 = moment('2012-01-15T00:00:00.000Z'),
m2 = moment('2012-02-13T00:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

assert.equal(d.as('days'), 29);
});

test('hour diff', function (assert) {
var m1 = moment('2012-01-15T17:00:00.000Z'),
m2 = moment('2012-01-16T03:00:00.000Z'),
d = moment.duration({from: m1, to: m2});

assert.equal(d.as('hours'), 10);
});

test('minute diff', function (assert) {
var m1 = moment('2012-01-15T17:45:00.000Z'),
m2 = moment('2012-01-16T03:15:00.000Z'),
d = moment.duration({from: m1, to: m2});

assert.equal(d.as('hours'), 9.5);
});
Loading

0 comments on commit 7ce3fa7

Please sign in to comment.