This commit is contained in:
Timo Hocker 2020-03-04 13:31:32 +01:00
parent 2bb71aeafd
commit 6777473b75
2 changed files with 35 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/node_modules/
/dist/
/.nyc_output/
/coverage/

32
test/index.js Normal file
View File

@ -0,0 +1,32 @@
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* Created by Timo Hocker <timo@scode.ovh>, March 2020
*/
/* eslint-disable no-magic-numbers */
// @ts-nocheck
'use strict';
const test = require ('ava');
const util = require ('../index');
test ('truncate_decimal', (t) => {
const trunc = util.truncate_decimal (1.23456, 2);
t.is (trunc, 1.23);
});
test ('try_parse_json should parse', (t) => {
const str = '{"test":"foo"}';
t.notThrows (() => {
const json = util.try_parse_json (str);
t.deepEqual (json, { test: 'foo' });
});
});
test ('try_parse_json should fail', (t) => {
const str = '{"test":foo"}';
t.notThrows (() => {
const json = util.try_parse_json (str);
t.is (json, null);
});
});