mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
34 lines
747 B
JavaScript
34 lines
747 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>'}
|
||
|
]
|
||
|
);
|
||
|
|
||
|
it('handles invalid query', () => {
|
||
|
expect(() => query('<hi>there</hi>', '//[]')).toThrowError('Invalid XPath query: //[]');
|
||
|
});
|
||
|
});
|