UNPKG

@pact-foundation/pact

Version:
107 lines 5.74 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const MatchersV3 = __importStar(require("../v3/matchers")); const xmlElement_1 = require("./xmlElement"); const xmlText_1 = require("./xmlText"); describe('xml element', () => { describe('appendText', () => { it('can be called with a string', () => { const xml = new xmlElement_1.XmlElement('my name') .appendText('some string') .appendText('second string'); expect(xml, 'XML element').toHaveProperty('name'); expect(xml.name, 'name of XML element').toBe('my name'); expect(xml, 'XML element').toHaveProperty('children'); expect(xml.children, 'children of XML element').toHaveLength(2); expect(xml.children[0], 'type of first child of XML element').toBeInstanceOf(xmlText_1.XmlText); expect(xml.children[0], 'first child of XML element').toHaveProperty('content'); expect(xml.children[0].content, 'content of first child').toBe('some string'); expect(xml.children[0], 'first child of XML element').toHaveProperty('matcher'); expect(xml.children[0].matcher, 'matcher of the first child').toBeUndefined(); }); it('can be called with a Matcher', () => { const xml = new xmlElement_1.XmlElement('my name') .appendText(MatchersV3.string('string matcher')) .appendText(MatchersV3.regex(/^.*$/, 'regex matcher')) .appendText(MatchersV3.date('yyyy-MM-dd HH:mm:ss.SSSX', '2016-02-11T09:46:56.023Z')) .appendText(MatchersV3.datetime('yyyy-MM-dd HH:mm:ss.SSSX', '2016-02-11T09:46:56.023Z')) .appendText(MatchersV3.timestamp('yyyy-MM-dd HH:mm:ss.SSSX', '2016-02-11T09:46:56.023Z')) .appendText(MatchersV3.time('yyyy-MM-dd HH:mm:ss.SSSX', '2016-02-11T09:46:56.023Z')) .appendText(MatchersV3.uuid('adc214d3-1c9f-460d-b6c8-8f2bc8911860')); expect(xml, 'XML element').toHaveProperty('name'); expect(xml.name, 'name of XML element').toBe('my name'); expect(xml, 'XML element').toHaveProperty('children'); expect(xml.children, 'children of XML element').toHaveLength(7); for (let i = 0; i < 7; i += 1) { const child = xml.children[i]; expect(child).toBeInstanceOf(xmlText_1.XmlText); expect(child).toHaveProperty('content'); expect(child.content).not.toBe(''); expect(child.content).toBeTypeOf('string'); expect(child).toHaveProperty('matcher'); expect(child.matcher).toHaveProperty('value'); expect(child.matcher?.value).toBeTypeOf('string'); expect(child.matcher?.value).not.toBe(''); expect(child.matcher).toHaveProperty('pact:matcher:type'); expect(child.matcher?.['pact:matcher:type']).toBeTypeOf('string'); expect(child.matcher?.['pact:matcher:type']).not.toBe(''); } }); it('sets content to an empty string if the Matcher has no value', () => { function noValueMatcher() { return { 'pact:matcher:type': 'no-value', }; } const xml = new xmlElement_1.XmlElement('my name').appendText(noValueMatcher()); expect(xml, 'XML element').toHaveProperty('name'); expect(xml.name, 'name of XML element').toBe('my name'); expect(xml, 'XML element').toHaveProperty('children'); expect(xml.children, 'children of XML element').toHaveLength(1); const child = xml.children[0]; expect(child).toBeInstanceOf(xmlText_1.XmlText); expect(child).toHaveProperty('content'); expect(child.content).toBe(''); expect(child.content).toBeTypeOf('string'); expect(child).toHaveProperty('matcher'); expect(child.matcher).not.toHaveProperty('value'); expect(child.matcher).toHaveProperty('pact:matcher:type'); expect(child.matcher?.['pact:matcher:type']).toBeTypeOf('string'); expect(child.matcher?.['pact:matcher:type']).not.toBe(''); }); }); }); //# sourceMappingURL=xmlElement.spec.js.map