Event JSON
{
"id": "0f7c68ea03e08f3122a35c6a980bb4a07b0deb0a8c06cb40b4f770051c0c8356",
"pubkey": "bb1742d1b321126a78c9a65acb9b810a49693c1b76b6446ae059fc3ff0cc2bf2",
"created_at": 1717809918,
"kind": 1,
"tags": [
[
"proxy",
"https://techhub.social/@develwithoutacause/112578390815261965",
"web"
],
[
"t",
"jest"
],
[
"t",
"javascript"
],
[
"t",
"testing"
],
[
"t",
"jasmine"
],
[
"t",
"go"
],
[
"t",
"idea"
],
[
"proxy",
"https://techhub.social/users/develwithoutacause/statuses/112578390815261965",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://techhub.social/users/develwithoutacause/statuses/112578390815261965",
"pink.momostr"
]
],
"content": "#JavaScript #Testing #Idea: Instead of manually managing `beforeEach` and `afterEach` in #Jest / #Jasmine / etc., what if we had a way to register a \"run this on test cleanup\" callback at any time? Kind of like how `defer` in #Go will automatically clean up a resource at the end of a function.\n\n```javascript\nit('does a thing', () =\u003e {\n const thing = createAThing();\n useTheThing(thing);\n});\n\nfunction createAThing() {\n const thing = makeThing();\n jasmine.afterThisTest(() =\u003e thing.cleanup());\n return thing;\n}\n```\n\nThis feels much more ergonomic and allows you to create resources without messing up your scoping with `beforeEach` / `afterEach`.\n\nHas anyone tried this? I don't think I've seen this pattern in a JS testing context.",
"sig": "224d485bec21a88f5c0984acd3fcdb1531c66790a98cf2b9dc7452b86321a5736c77c590945da75c79bfafe058ca278ed3e22e02792f226b1351231125dfaea1"
}