curriculum/challenges/english/blocks/quality-assurance-and-testing-with-chai/5f8884f4c46685731aabfc41.md
As a reminder, this project is being built upon the following starter project cloned from <a href="https://github.com/freeCodeCamp/boilerplate-mochachai/" target="_blank" rel="noopener noreferrer nofollow">GitHub</a>.
Within tests/2_functional-tests.js, in the 'Submit the surname "Vespucci" in the HTML form' test (// #6), automate the following:
VespucciAnd within the pressButton callback:
200span#name is 'Amerigo'span#surname is 'Vespucci'span#dates exist and their count is 1Do not forget to remove the assert.fail() call.
All tests should pass.
const response = await fetch(code + '/_api/get-tests?type=functional&n=6');
if (!response.ok) {
throw Error(await response.text());
}
const data = await response.json();
assert.equal(data.state, 'passed');
You should assert that the headless browser request succeeded.
const response = await fetch(code + '/_api/get-tests?type=functional&n=6');
if (!response.ok) {
throw Error(await response.text());
}
const data = await response.json();
assert.equal(data.assertions[0].method, 'browser.success');
You should assert that the text inside the element span#name is 'Amerigo'.
const response = await fetch(code + '/_api/get-tests?type=functional&n=6');
if (!response.ok) {
throw Error(await response.text());
}
const data = await response.json();
assert.equal(data.assertions[1].method, 'browser.text');
assert.match(data.assertions[1].args[0], /('|")span#name\1/);
assert.match(data.assertions[1].args[1], /('|")Amerigo\1/);
You should assert that the text inside the element span#surname is 'Vespucci'.
const response = await fetch(code + '/_api/get-tests?type=functional&n=6');
if (!response.ok) {
throw Error(await response.text());
}
const data = await response.json();
assert.equal(data.assertions[2].method, 'browser.text');
assert.match(data.assertions[2].args[0], /('|")span#surname\1/);
assert.match(data.assertions[2].args[1], /('|")Vespucci\1/);
You should assert that the element span#dates exist and its count is 1.
const response = await fetch(code + '/_api/get-tests?type=functional&n=6');
if (!response.ok) {
throw Error(await response.text());
}
const data = await response.json();
assert.equal(data.assertions[3].method, 'browser.elements');
assert.match(data.assertions[3].args[0], /('|")span#dates\1/);
assert.equal(data.assertions[3].args[1], 1);