meta {
name: cheerio
type: http
seq: 1
}
post {
url: https://echo.usebruno.com
body: text
auth: none
}
body:text {
Hello Bruno!
}
script:pre-request {
const cheerio = require('cheerio');
const $ = cheerio.load('Hello world
');
$('h2.title').text('Hello pre-request!');
$('h2').addClass('welcome');
bru.setVar("cheerio-test-pre-request", $.html());
}
script:post-response {
const cheerio = require('cheerio');
const $ = cheerio.load('Hello world
');
$('h2.title').text('Hello post-response!');
$('h2').addClass('welcome');
bru.setVar("cheerio-test-post-response", $.html());
}
tests {
const cheerio = require('cheerio');
test("cheerio html - from pre request script", function() {
const expected = 'Hello pre-request!
';
const html = bru.getVar('cheerio-test-pre-request');
expect(html).to.eql(expected);
});
test("cheerio html - from post response script", function() {
const expected = 'Hello post-response!
';
const html = bru.getVar('cheerio-test-post-response');
expect(html).to.eql(expected);
});
test("cheerio html - from tests", function() {
const expected = 'Hello Bruno!
';
const $ = cheerio.load(res.body);
expect($.html()).to.eql(expected);
});
}