UNPKG

xml-to-json-util

Version:

xml-to-json-util is a simple and efficient utility library for converting XML data to JSON format easily.

40 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const xml_to_json_util_1 = require("../xml-to-json-util/xml.to.json.util"); describe('FEATURE: xmlToJsonUtil', () => { describe('SCENARIO: xmlToJsonUtil is called with wrong xml parameter', () => { it('THEN: it should throw an error', () => { const xml = 1; expect(() => (0, xml_to_json_util_1.xmlToJsonUtil)(xml)).toThrowError("First paramater 'xml' must be a string"); }); }); describe('SCENARIO: xmlToJsonUtil is called with correct xml parameter', () => { it("THEN: it should return object with 'person' property and nested 'name', 'age', and 'city'", () => { const xml = `<person> <name>João</name> <age>30</age> <city>São Paulo</city> </person> `; const sut = (0, xml_to_json_util_1.xmlToJsonUtil)(xml); expect(sut).toHaveProperty('person'); expect(sut.person).toHaveProperty('name'); expect(sut.person).toHaveProperty('age'); expect(sut.person).toHaveProperty('city'); }); }); describe('SCENARIO: xmlToJsonUtil is called with valid parameters and regex replacements', () => { it("THEN: it should return object data without substring 'thisshouldberemoved:' in product property", () => { const xmlWithSubstring = `<thisshouldberemoved:product> <price>1.1</price> </thisshouldberemoved:product>`; const substringToRemove = 'thisshouldberemoved:'; expect(xmlWithSubstring.includes(substringToRemove)).toBeTruthy(); const regexReplacements = [/thisshouldberemoved:/g]; const sut = (0, xml_to_json_util_1.xmlToJsonUtil)(xmlWithSubstring, regexReplacements); expect(sut).toHaveProperty('product'); expect(sut.product).toHaveProperty('price'); }); }); }); //# sourceMappingURL=xml.to.json.util.spec.js.map