• NaN years ago - link
    by @ghost

    Defining the jest spec

    A "spec" is just a test file. We call it "spec", short for "specification", because well written tests clearly define the behavior of a function.

    There is no need for comments or guessing. The function does exactly what the spec says it will do. This also means we can change the inner implementation of the function at any time as long as it still meets the spec.

    The test cases in the spec run against your code to ensure this.

    To define a test case, we need to define the input value and the output value we are validating the function against.

    Here are some simple tests that confirm the filters parameter is converted to the type required by the search feature. I'm essentially taking the example I gave before but writing it in code.

    With our tests defined, we can now see clearly how this function is intended to work.