From 6777473b75ed33c9abd6c6fe6b5249b61ff85798 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Wed, 4 Mar 2020 13:31:32 +0100 Subject: [PATCH] fix --- .gitignore | 4 +++- test/index.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/index.js diff --git a/.gitignore b/.gitignore index c85804c..e5c296b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /node_modules/ -/dist/ \ No newline at end of file +/dist/ +/.nyc_output/ +/coverage/ diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..faca10e --- /dev/null +++ b/test/index.js @@ -0,0 +1,32 @@ +/* + * Copyright (C) Sapphirecode - All Rights Reserved + * Created by Timo Hocker , 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); + }); +});