-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.js
43 lines (38 loc) · 1.65 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs= require('fs')
const capitalize = require('capitalize')
require('./postinstall')
files = fs.readdirSync('./units')
files.forEach(file => {
// file = "temperature.json"
describe(`mezur/${file}`, () => {
const units = require('./units/' + file)
const mezuringScope = require('./' + file.split('.')[0])
units.map(u1 => {
units.map(u2 => {
it(`converts from 1 ${u1.name} to ${u2.name}, "in" method`, () => {
expect(mezuringScope[u1.name + 's'](1)[`in${capitalize(u2.name + 's')}`]()).toMatchSnapshot()
})
it(`converts from 1 ${u1.name} to ${u2.name}, "as" method`, () => {
expect(mezuringScope[u1.name + 's'](1)[`as${capitalize(u2.name + 's')}`]()).toMatchSnapshot()
})
it(`converts from 1 ${u1.name} to ${u2.name}, "to" method`, () => {
expect(mezuringScope[u1.name + 's'](1)[`to${capitalize(u2.name + 's')}`]()).toMatchSnapshot()
})
})
})
})
})
describe('extend units', () => {
it('uses the new time units', () => {
const marsUnits = [
{ name: 'martianDay', symbol: 'marsd', value: '24h + 39m + 35.244s' },
{ name: 'martianWeek', symbol: 'marsw', value: '7marsd' },
{ name: 'martianYear', symbol: 'marsY', value: '668.5991marsd' }
]
const timeUnits = require('./units/time.json') // note that angles is a js file, so PI calculates will be accurate
const marsTime = require('.')(timeUnits.concat(marsUnits))
expect(marsTime.martianYears(1).inMartianDays()).toEqual(668.5991)
expect(marsTime.martianDays(14).inMartianWeeks()).toEqual(2)
expect(marsTime.martianYears(1).inSeconds()).toEqual(59355048.240680404)
})
})