Search code examples
javascriptteaspoon

How to use Teaspoon for JS testing


I'm new to JS testing and I would like to understand how to test a JS function I have. I'm using Teaspoon-mocha as the testing library and the function I would like to test is:

var C_FORM = "http://www.exmple.com/SomeForm#Form";
    function getNamespace(uri) {
      var parts = uri.split("#");
      if (parts.length == 2) {
        return parts[0];
      } else {
        return "";
      }
    }

I would like to have an example how to test this specific function. This function actually getNamespace from the final part of a specific URI which is defined by that var C_FORM so the result is that is getting the namespace which is Form. I would like to test this function if it is doing this by Teaspoon but as above I'm not familiar with this kind of testing, I need just an example to get familiar.

I tried the next solution but I get that equal is undefined:

describe("Application", function() {

  it("Gets Namespace", function() {
    var uri = "http://www.test.com/SomeTest#Test";

    expect(getNamespace(uri).to.equal("http://www.test.com/SomeTest"))

  })

});

Solution

  • Please try this way:

    expect(getNamespace(uri)).to.equal("http://www.test.com/SomeTest")