Skip to content Skip to sidebar Skip to footer

Unable To Identify Whether My Test Case Pass Or Fail

I need to test 'Events' in JavaScript like Button click, by clicking link..etc using 'Mocha'. I've 3 files 1) Login.html, 2) Application.js, 3) test.js. 1) Application.js file con

Solution 1:

Two things:

  1. doClick()

The innerHTML value is what displays on the actual Button, not what runs when the button is clicked. You don't have to do or set anything else to get to that functionality; that's what your addEventListener call is doing. If you want to display an alert, all doclick needs to do is:

function doclick() {
    alert("Going to test Events in JavaScript");
}
  1. test.js

Now, it looks like you want doclick to do more than just send the alert, and also return a value to be used in test.js. Does this need to be that string? Given that doclick only does one thing, Not really. If all you want to do is test that it ran, have doclick return true and set v1 to false initially. Then set your v1 to expect a value of true rather than that long string.

function doclick() {
    alert("Going to test Events in JavaScript");
    return true; //I ran, so return true.
}

var expect = chai.expect;

describe('Testing', function() {
  it('Testing the Events in JavaScript', function() {

    var v1 = false;
    v1 = doclick();
    expect(v1).to.equal(true); //or whatever the syntax here is, I haven't used expect before

  });
});

I'm assuming the rest of your syntax is correct - that "it()" is a valid function and that your test.js file does ultimately run without error. If someone with more knowledge of Mocha wants to answer I'd probably take their knowledge over mine, but given no one else has answered so far it's at least a starting point to address some of the JS code-related issues!


Post a Comment for "Unable To Identify Whether My Test Case Pass Or Fail"