
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
A small library to help Jest support given-when-then style testing without a bunch of overhead
A small library to help Jest support given-when-then style testing without a bunch of overhead
| jest-gwt Version | Jest Version |
|---|---|
| 1.x | 24.x, 25.x |
| 2.x | 26.x, 27.x |
| 3.x | > 26.x |
npm i --save-dev jest-gwt
test
import test from 'jest-gwt';
describe('test context', () => {
test('has no expected errors', {
given: {
mock_jest_test_function,
GOOD_test_case,
},
when: {
executing_test_case,
},
then: {
all_GIVENS_called,
all_WHENS_called,
all_THENS_called,
},
});
});
Sometimes a GWT flow doesn't make sense. You might be writing integration tests. Or something that needs to assert something, then do another thing, then assert something else.
In these cases, you can use the scenario definition style which allows chaining
when and then, followed by then_when and then blocks.
{
given: {
mock_jest_test_function,
GOOD_test_case,
},
scenario: [{
when: {
executing_test_case,
},
then: {
assert_something,
},
}, {
then_when: {
user_submits_form,
},
then: {
something_else_happens,
yet_another_thing_is_true,
},
}, {
then_when: {
something_happens,
},
then: {
expect_error: some_check,
and: {
something_is_still_true,
},
}
}]
}
Sometimes you want a test to be disabled in code. Jest offers this functionality with
the xtest method, and we've duplicated this logic, but with strong typing so you can
disable your gwt style tests.
import test, { xtest } from 'jest-gwt';
describe('test context', () => {
test('this test will run', {
then: {
CANARY,
},
});
xtest('this test will NOT run', {
when: {
oops_we_broke_this,
},
});
});
withAspect wraps up jest's beforeEach and afterEach to allow preparing and
cleaning up the context before running tests.
withAspect(
// this is the beforeEach. Do your prep work here
function(this: Context) {
},
// this is the afterEach. It is OPTIONAL. If you need to do clean up of
// external resources you allocated in the beforeEach, do it here
function(this: Context) {
}
)
The afterEach has access to whatever values you put on the Context in the
beforeEach. It does NOT have access to the values put on the Context during
the specific test.
Please refer to gwt-runner for detailed usage on how to write tests and clauses.
FAQs
A small library to help Jest support given-when-then style testing without a bunch of overhead
The npm package jest-gwt receives a total of 133 weekly downloads. As such, jest-gwt popularity was classified as not popular.
We found that jest-gwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.