Skip to content

Commit

Permalink
Add util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Nov 7, 2017
1 parent cb08984 commit 0c5a093
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, it } from 'mocha'
import { expect } from 'chai'

import { cmd, niceDate, removeIndentation, isLink } from '../src/utils'

describe('cmd', () => {
it('runs a command', async () => {
const result = await cmd('node --version')
expect(result).to.be.a('string')
})
})

describe('niceDate', () => {
it('formats string into nice date', () => {
expect(niceDate('2015-10-03')).to.equal('3 October 2015')
expect(niceDate('2017-11-07T19:19:02.635Z')).to.equal('7 November 2017')
})

it('formats date into nice date', () => {
expect(niceDate(new Date(2016, 8, 2))).to.equal('2 September 2016')
expect(niceDate(new Date('2015-10-03'))).to.equal('3 October 2015')
})
})

describe('removeIndentation', () => {
it('removes indentation', () => {
const input = ' some\n indented\n text'
const expected = 'some\nindented\ntext'
expect(removeIndentation(input)).to.equal(expected)
})
})

describe('isLink', () => {
it('returns true for links', () => {
expect(isLink('http://test.com')).to.equal(true)
})

it('returns false for non-links', () => {
expect(isLink('not a link')).to.equal(false)
})
})

0 comments on commit 0c5a093

Please sign in to comment.