I am extremely new to web development and testing (starting slow). I have a page with a button. Once the button is clicked, some information/text is displayed.
How do I write a test case to test that the output is as expected (that its displayed)?
I want to write a test case to make sure that the text is displayed when the button is clicked.
<!DOCTYPE html>
<html>
<body>
<button onclick="buttonClick()">Click Me</button>
<p id="test"></p>
<script>
function buttonClick() {
document.getElementById("test").innerHTML = "TESTING!";
}
</script>
</body>
</html>
My guess is that I could use some sort of string verifier. If strings are present on the screen, that means the test passed. I am unsure if that makes sense, or if it is the correct approach.
Thanks,
Code for testing:
var elem = document.getElementById('test');
var text = 'TESTING!';
if (
document.getElementById('test').innerHTML.indexOf('TESTING') != -1){
alert('success!');
}