const { query } = require('..');
function q(description, args, result) {
it(description, () => {
expect(query(...args)).toEqual(result);
});
}
describe('query()', () => {
q('handles missing query', [''], []);
q(
'handles basic query',
['foobar', '//y'],
[
{ inner: 'foo', outer: 'foo' },
{ inner: 'bar', outer: 'bar' },
],
);
q(
'handles attribute query',
['foobar', '//*[@foo="bar"]'],
[{ inner: 'foo', outer: 'foo' }],
);
q(
'handles string query',
['foobar', 'substring(//y[1], 2)'],
[{ inner: 'oo', outer: 'oo' }],
);
it('handles invalid query', () => {
expect(() => query('there', '//[]')).toThrowError('Invalid XPath query: //[]');
});
});