mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
41 lines
887 B
JavaScript
41 lines
887 B
JavaScript
const {query} = require('..');
|
|
|
|
function q (description, args, result) {
|
|
it(description, () => {
|
|
expect(query(...args)).toEqual(result);
|
|
});
|
|
}
|
|
|
|
describe('query()', () => {
|
|
q('handles missing query',
|
|
['<foo><bar></bar></foo>'],
|
|
[]
|
|
);
|
|
|
|
q('handles basic query',
|
|
['<x><y>foo</y><y>bar</y></x>', '//y'],
|
|
[
|
|
{inner: 'foo', outer: '<y>foo</y>'},
|
|
{inner: 'bar', outer: '<y>bar</y>'}
|
|
]
|
|
);
|
|
|
|
q('handles attribute query',
|
|
['<x><y foo="bar">foo</y><y hi="there">bar</y></x>', '//*[@foo="bar"]'],
|
|
[
|
|
{inner: 'foo', outer: '<y foo="bar">foo</y>'}
|
|
]
|
|
);
|
|
|
|
q('handles string query',
|
|
['<x><y>foo</y><y>bar</y></x>', 'substring(//y[1], 2)'],
|
|
[
|
|
{inner: 'oo', outer: 'oo'}
|
|
]
|
|
);
|
|
|
|
it('handles invalid query', () => {
|
|
expect(() => query('<hi>there</hi>', '//[]')).toThrowError('Invalid XPath query: //[]');
|
|
});
|
|
});
|