Skip to content

Commit

Permalink
adding initial mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Schenk committed Nov 6, 2018
1 parent bf806c6 commit 85b566e
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 1 deletion.
188 changes: 188 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"main": "moment-feiertage.js",
"homepage": "https://github.com/DaniSchenk/moment-feiertage",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"repository": {
"type": "git",
Expand All @@ -32,5 +32,8 @@
"license": "ISC",
"dependencies": {
"moment": "^2.15.1"
},
"devDependencies": {
"mocha": "^5.2.0"
}
}
64 changes: 64 additions & 0 deletions test.js
@@ -0,0 +1,64 @@
const assert = require('assert');
const moment = require('moment');
const {
isHoliday
} = require('./moment-feiertage');

const allStates = ['BW', 'BY', 'BE', 'BB', 'HB', 'HH', 'HE', 'MV', 'NI', 'NW', 'RP', 'SL', 'SN', 'ST', 'SH', 'TH'];
// test some non-holiday dates
it('should return false', () => {
assert.equal(false, moment('2017-01-03').isHoliday());
assert.deepEqual({
allStates: false,
holidayName: '',
holidayStates: [],
testedStates: allStates
}, moment('2017-01-03').isHoliday([]));

for(const s of allStates) {
assert.equal(false, moment('2017-01-03').isHoliday(s));
assert.deepEqual({
allStates: false,
holidayName: '',
holidayStates: [],
testedStates: [s]
}, moment('2017-01-03').isHoliday([s]));
}
});
// test Christmas
it('should return Christmas', () => {
assert.equal('1. Weihnachtsfeiertag', moment('2019-12-25').isHoliday());
assert.deepEqual({
allStates: true,
holidayName: '1. Weihnachtsfeiertag',
holidayStates: allStates,
testedStates: allStates
}, moment('2019-12-25').isHoliday([]));

for(const s of allStates) {
assert.equal('1. Weihnachtsfeiertag', moment('2019-12-25').isHoliday(s));
assert.deepEqual({
allStates: true,
holidayName: '1. Weihnachtsfeiertag',
holidayStates: [s],
testedStates: [s]
}, moment('2019-12-25').isHoliday([s]));
}
});

// test Christmas
it('should return correct Object', () => {
assert.deepEqual({
allStates: false,
holidayName: 'Allerheiligen',
holidayStates: [ 'BW', 'BY', 'NW', 'RP', 'SL' ],
testedStates: allStates
}, moment('2018-11-01').isHoliday([]));

assert.deepEqual({
allStates: false,
holidayName: 'Allerheiligen',
holidayStates: [ 'BW' ],
testedStates: ['BW', 'SH', 'TH']
}, moment('2018-11-01').isHoliday(['BW', 'SH', 'TH']));
});

0 comments on commit 85b566e

Please sign in to comment.