Skip to content

Commit

Permalink
start adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed May 30, 2019
1 parent 40eb654 commit b04455b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--require ts-node/register
--require test/setup.ts
--recursive
--exit
25 changes: 25 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

import * as chai from 'chai';
// @ts-ignore
import * as dirtyChai from 'dirty-chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as path from 'path';
// @ts-ignore
import * as mod from 'module';
// @ts-ignore
import * as sinon from 'sinon';
// @ts-ignore
import * as sinonChai from 'sinon-chai';

chai.use(sinonChai);
chai.use(chaiAsPromised);
chai.use(dirtyChai);

(global as any).should = chai.should();
(global as any).sinon = sinon;

// importing files with ../../../../../.. makes my brain hurt
process.env.NODE_PATH = path.join(__dirname, '..') + path.delimiter + (process.env.NODE_PATH || '');
// @ts-ignore
mod._initPaths();
39 changes: 39 additions & 0 deletions test/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

import {CronicleClient} from '../../dist/';
import moment = require('moment');
import {expect} from 'chai';

describe('index', () => {

describe('timing helpers ', () => {

it('should create timing object from moment', () => {
const timing = CronicleClient.getUtcTiming(moment.utc('2016-05-26T14:50:50.900Z'));
expect(timing.years![0]).to.eq(2016);
expect(timing.months![0]).to.eq(5);
expect(timing.days![0]).to.eq(26);
expect(timing.hours![0]).to.eq(14);
expect(timing.minutes![0]).to.eq(50);
});

it('should create timing object from date', () => {
const timing = CronicleClient.getUtcTiming(new Date('2016-05-26T14:50:50.900Z'));
expect(timing.years![0]).to.eq(2016);
expect(timing.months![0]).to.eq(5);
expect(timing.days![0]).to.eq(26);
expect(timing.hours![0]).to.eq(14);
expect(timing.minutes![0]).to.eq(50);
});

it('should create timing object from string', () => {
const timing = CronicleClient.getUtcTiming('2016-05-26T14:50:50.900Z');
expect(timing.years![0]).to.eq(2016);
expect(timing.months![0]).to.eq(5);
expect(timing.days![0]).to.eq(26);
expect(timing.hours![0]).to.eq(14);
expect(timing.minutes![0]).to.eq(50);
});

});
});

0 comments on commit b04455b

Please sign in to comment.