Search code examples
angularjasminekarma-jasminekarma-coverage

How to write unit test case in jasmine?


Flag(a) {
           let element=this.selected.filter(item => item.a=== a)
           return element.length > 1 ? true : false;
        }

Not sure how to write a unit test case for the above function. Can you please help


Solution

  • A test case consists always of 3 steps:

    • Preparation
    • Execution
    • Verification

    In your case this means:

    • Preparation: set the value of this.selected
    • Execution: call Flag with a defined a
    • Verification: check the function return false