0

I'm wondering if/how i can use Sinon to stub the object mappedValues nested in the function below:

function getValueFromObj(key) {
    var mappedValues = {
        "a": "aaa",
        "b": "bbb",
        "c": "ccc",
        "d": "ddd",
    };

    return mappedValues[key];
}

My goal for the test is not to check each value but rather just make sure that when passed a key a correctly corresponding value is returned and the value is not augmented in any way.

I think the best way to test this is to have the test stub mappedValues and then check the return value of getValueFromObj but i'm not sure how to actually stub the object.

Billy Blob Snortin
  • 1,101
  • 3
  • 11
  • 17

1 Answers1

0

I don't think is a good idea to use sinon for this purpose. I think you can simply write a test like this:

expect(getValueFromObj("a")).to.eql("aaa");

when this expectation (i use chai expect to write that) is satisfied you are sure that all work correctly.

Antonio Ganci
  • 515
  • 5
  • 16