Conventional testing frameworks depend on you for the actual and the expected. Put differently: you have to write
test code and predict the outcome. bancheck
expects your code to work, and because it does it only depends on you for
the actual.
That's your responsibilities cut in half right there. Writing tests becomes easier, as does maintaining tests.
Say you have a function splitName
which takes a human-inputted name and splits it into its different parts.
These are two tests:
const {test, expect} = require('bancheck');
test({
pimm: splitName('Pimm Hogeling'),
vincent: splitName('Vincent van Gogh')
})
This is the output:
{
"passes": {
"pimm": "Object {\
\"familyName\": \"Hogeling\",\
\"givenName\": \"Pimm\",\
}",
"vincent": "Object {\
\"familyName\": \"van Gogh\",\
\"givenName\": \"Vincent\",\
}"
},
"fails": {}
}
Just double-check those passes and you are set.
Now say later you come to your senses and realise the "van" in "Vincent van Gogh" is actually not part of his family name, but rather a tussenvoegsel.
Simply change splitName
and re-run the test. This is the output:
{
"passes": {
"pimm": "Object {\
\"familyName\": \"Hogeling\",\
\"givenName\": \"Pimm\",\
}"
},
"fails": {
"vincent": {
"expected": "Object {\
\"familyName\": \"van Gogh\",\
\"givenName\": \"Vincent\",\
}",
"actual": "Object {\
\"familyName\": \"Gogh\",\
\"givenName\": \"Vincent\",\
\"tussenvoegsels\": \"van\",\
}",
"diff": …
}
}
}
One test fails, but not because your function is broken. The test is outdated. Update it by calling expect
instead of
test
:
const {test, expect} = require('bancheck');
expect({
pimm: splitName('Pimm Hogeling'),
vincent: splitName('Vincent van Gogh')
})
This is the output:
{
"passes": {
"pimm": "Object {\
\"familyName\": \"Hogeling\",\
\"givenName\": \"Pimm\",\
}",
"vincent": "Object {\
\"familyName\": \"Gogh\",\
\"givenName\": \"Vincent\",\
\"tussenvoegsel\": \"van\",\
}"
},
"fails": {}
}
The tests have been updated, and you can call test
again from this point on.
bancheck
exports a test
and an expect
function. You can include test runs in your build script. If you are looking
for a ready-to-go command-line interface, check out jest-cli.
bancheck
saves the expected data in a snapshot file located at bancheck/snapshots.snap
. You probably want to
distribute that file along with your source code.