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: []
}
Just put them inside the inspect as variables
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: []
}
When an expect fails, it will also print any variables within the expect scope.
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: []
}
Thanks that a lot better
Last updated: Jul 06 2025 at 12:14 UTC