Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('parses self::', () => {
const element = documentNode.createElement('someElement');
chai.assert.deepEqual(evaluateXPathToFirstNode('self::someElement', element), element);
});
it('throws the correct error if context is absent', () => {
it('can parse a simple any element + attribute selector', () => {
const element = documentNode.createElement('someElement');
element.setAttribute('someAttribute', 'someValue');
chai.assert.deepEqual(evaluateXPathToFirstNode('self::*[@someAttribute=\'someValue\']', element), element);
const comment = documentNode.createComment('someComment');
chai.assert.deepEqual(evaluateXPathToNodes('self::*[@someAttribute=\'someValue\']', comment), []);
});
it('uses correct contexts in predicates', () => {
jsonMlMapper.parse([
'someGrandParentElement',
[
'someParentElement',
['someChildelement']
]
], documentNode);
chai.assert.deepEqual(evaluateXPathToFirstNode('parent::someParentElement[parent::someGrandParentElement]', documentNode.documentElement.firstChild.firstChild), documentNode.documentElement.firstChild);
});
it('Keeps nodes nodes', () =>
chai.assert.equal(
evaluateXPathToFirstNode('.', documentNode, domFacade),
documentNode
));
it('Throws when the xpath resolves to an attribute', () => {
jsonMlMapper.parse(
[
'someElement',
{
someAttribute: 'someValue'
}
],
documentNode
);
chai.assert.equal(
evaluateXPathToFirstNode('//@someAttribute', documentNode, domFacade),
documentNode.documentElement.attributes[0]
);
});
it('Throws when the xpath resolves to not a node', () => {
it('sets the context sequence', () => {
jsonMlMapper.parse([
'someParentElement',
['someElement'],
['someOtherElement']
], documentNode);
chai.assert.deepEqual(evaluateXPathToFirstNode('someParentElement/child::*[last()]', documentNode), documentNode.documentElement.lastChild);
});
it('throws the correct error if context is absent', () => {
it('returns the root of the given document', () =>
chai.assert.equal(evaluateXPathToFirstNode('root(.)', documentNode), documentNode));
it('can create an element', () => {
chai.assert.equal(
evaluateXPathToFirstNode(
'<element>',
documentNode,
undefined,
{},
{ language: evaluateXPath.XQUERY_3_1_LANGUAGE }
).nodeType,
1
);
});
it('Sets the correct name', () => {</element>
function getAsserterForTest(baseUrl, testCase, language) {
return createAsserter(baseUrl, evaluateXPathToFirstNode('./result/*', testCase), language);
}
if (isUpdating) {
const it = await evaluateUpdatingExpression(...args);
xdmValue = it.xdmValue;
if (it.pendingUpdateList) {
executePul(it.pendingUpdateList, args);
}
xdmValue.forEach(nodeValue => {
if (nodeValue.value.normalize) {
nodeValue.value.normalize();
}
});
}
switch (outputFile.compare) {
case 'XML': {
const actual = xdmValue ? xdmValue[0].value : evaluateXPathToFirstNode(...args);
const expected = actual.nodeType === actual.DOCUMENT_NODE ?
parser.parseFromString(expectedString) :
parser.parseFromString(expectedString).documentElement;
catchAssertion(() => assertXml(actual, expected));
break;
}
case 'Fragment': {
const actualNodes = xdmValue ? xdmValue.map(nodeValue => nodeValue.value) : evaluateXPathToNodes(...args);
catchAssertion(() => assertFragment(actualNodes, expectedString));
break;
}
case 'Text': {
if (xdmValue) {
throw new Error('Not yet supported: Updating query with text assertion.');