Stream: beginners

Topic: What is a better way to layout a test?


view this post on Zulip Ashley Davis (Jul 04 2024 at 22:04):

I've started the second test for my second ever Roc function which I'm building up test by test in the TDD style.

I don't want to include long inputs as arguments to the expect function. So I've pulled these out to globals. That's not great because on my next test I'm not going to be able to use the same names.

Is there a better idiomatic way to structure a test like this:

# No items left returns current row.
currentRowItems = [{}, {}, {}]
removedItems = [{}, {}]
headings = ["a", "b"]
expect getNextRow [] 10 21 currentRowItems 12 removedItems headings == {
    row: {
        items: currentRowItems,
        offsetY: 0,
        height: 21,
        currentRowItems: [],
        width: 12,
        headings
    },
    removedItems,
    remainingItems: []
}

view this post on Zulip Brendan Hansknecht (Jul 04 2024 at 22:05):

Just put them inside the inspect as variables

view this post on Zulip Brendan Hansknecht (Jul 04 2024 at 22:06):

expect
    currentRowItems = [{}, {}, {}]
    removedItems = [{}, {}]
    headings = ["a", "b"]
    getNextRow [] 10 21 currentRowItems 12 removedItems headings == {
        row: {
            items: currentRowItems,
            offsetY: 0,
            height: 21,
            currentRowItems: [],
            width: 12,
            headings
        },
        removedItems,
        remainingItems: []
    }

view this post on Zulip Brendan Hansknecht (Jul 04 2024 at 22:06):

When an expect fails, it will also print any variables within the expect scope.

view this post on Zulip Brendan Hansknecht (Jul 04 2024 at 22:07):

So it is often nice to do:

expect
    currentRowItems = [{}, {}, {}]
    removedItems = [{}, {}]
    headings = ["a", "b"]
    out = getNextRow [] 10 21 currentRowItems 12 removedItems headings
    out == {
        row: {
            items: currentRowItems,
            offsetY: 0,
            height: 21,
            currentRowItems: [],
            width: 12,
            headings
        },
        removedItems,
        remainingItems: []
    }

view this post on Zulip Ashley Davis (Jul 04 2024 at 22:12):

Thanks that a lot better


Last updated: Jul 06 2025 at 12:14 UTC