UNPKG

einvoicing

Version:

A JavaScript library for creating and parsing electronic invoices compliant with the eInvoicing Directive, EN 16931, and popular extensions

46 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var helpers_1 = require("./helpers"); describe('helpers', function () { test('strOrUnd', function () { expect((0, helpers_1.strOrUnd)(null)).toBe(undefined); expect((0, helpers_1.strOrUnd)(undefined)).toBe(undefined); expect((0, helpers_1.strOrUnd)({ '#text': 'test' })).toBe('test'); expect(function () { return (0, helpers_1.strOrUnd)({}); }).toThrow('Invalid node'); }); test('numOrUnd', function () { expect((0, helpers_1.numOrUnd)(null)).toBe(undefined); expect((0, helpers_1.numOrUnd)(undefined)).toBe(undefined); expect((0, helpers_1.numOrUnd)({ '#text': '1' })).toBe(1); expect(function () { return (0, helpers_1.strOrUnd)({}); }).toThrow('Invalid node'); }); test('getArray', function () { var node1 = { 'cac:TaxTotal': { 'cac:TaxSubtotal': { 'cbc:TaxableAmount': 1 } } }; var node2 = { 'cac:TaxTotal': { 'cac:TaxSubtotal': [{ 'cbc:TaxableAmount': 1 }, { 'cbc:TaxableAmount': 2 }] } }; expect((0, helpers_1.getArray)(node1, ['cac:TaxTotal', 'cac:TaxSubtotal'])).toEqual([ { "cbc:TaxableAmount": 1 } ]); expect((0, helpers_1.getArray)(node2, ['cac:TaxTotal', 'cac:TaxSubtotal'])).toEqual([ { "cbc:TaxableAmount": 1 }, { "cbc:TaxableAmount": 2 } ]); expect((0, helpers_1.getArray)({}, ['cac:TaxTotal', 'cac:TaxSubtotal'])).toEqual([]); }); }); //# sourceMappingURL=helpers.spec.js.map