import test from "tape"; import { scrap, $ } from '../lib'; const STR_TO_SCRAP = `

Hello

read more ... `; test('Basic', (main) => { test('should scrap

text from string', (t) => { const result = scrap(STR_TO_SCRAP, { title: $.text('h1.title') }); t.equal(result, { title: 'Hello'}); t.end(); }); test('should scrap attributes from

', (t) => { const result = scrap(STR_TO_SCRAP, { title: $.attr('h1.title', 'class') }); t.equal(result, { title: 'title'}); t.end(); }); test('should scrap items from ', (t) => { const result = scrap(STR_TO_SCRAP, { items: $.list('li', { text: $.text('span') }) }); t.equal(result.items.length, 3); t.equal(result.items[2].text, 'Bonjour'); t.end(); }); test('should scrap text from
  • ', (t) => { const result = scrap(STR_TO_SCRAP, { items: $.list('li', { text: $.text('span') }) }); t.equal(result.items.length, 3); t.equal(result.items[2].text, 'Bonjour'); t.end(); }); test('should scrap text from by omitting
  • ', (t) => { const result = scrap(STR_TO_SCRAP, { items: $.list('span', { text: $.text('') }) }); t.equal(result.items.length, 3); t.equal(result.items[2].text, 'Bonjour'); t.end(); }); test('should get list of texts', (t) => { const result = scrap(STR_TO_SCRAP, { texts: $.list('li', $.text('span')) }); t.equals(result.texts, [ 'Guten Tag', 'Ciao', 'Bonjour' ]); t.end(); }); test('should user deep query', (t) => { const result = scrap(STR_TO_SCRAP, { title: $.text('.title'), data: { msg: $.text('.msg') } }); t.equal(result.title, 'Hello'); t.equal(result.data.msg, 'Ciao'); t.end(); }); test('should count elements', (t) => { const result = scrap(STR_TO_SCRAP, { spanCount: $.count('span') }); t.equal(result.spanCount, 3); t.end(); }); test('should count not exists element', (t) => { const result = scrap(STR_TO_SCRAP, { spanCount: $.count('table') }); t.equal(result.spanCount, 0); t.end(); }); test('should use only selector to scrap title', (t) => { const title = scrap(STR_TO_SCRAP, $.text('.title')); t.equal(title, 'Hello'); }); test('should use only selector to scrap ', (t) => { const spans = scrap(STR_TO_SCRAP, $.list('span', $.text(''))); t.equal(spans.length, 3); t.equal(spans[0], 'Guten Tag'); t.end(); }); main.end(); });