npm.io
1.1.0 • Published 3 weeks ago

@quenty/jestutils

Licence
MIT
Version
1.1.0
Deps
4
Size
11 kB
Vulns
0
Weekly
0
Stars
610
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

JestUtils

Jest testing utilities for Nevermore packages

Installation

npm install @quenty/jestutils --save

Usage

JestUtils.afterThis queues a maid task next to the code that needs undoing. The queue unwinds in reverse once the current test finishes, pass or fail, so teardown mirrors setup.

local Jest = require("Jest")
local JestUtils = require("JestUtils")

local expect = Jest.Globals.expect
local it = Jest.Globals.it

it("reads back what it wrote", function()
	local store = DataStore.new()
	JestUtils.afterThis(store)

	local handle = store:GetHandle()
	JestUtils.afterThis(handle)

	expect(handle:Read()).toEqual(nil)
end)

Anything a Maid accepts works: a function, an Instance, an RBXScriptConnection, a thread, or a table with a Destroy method.

It returns a function that unqueues the task again, which is itself a maid task. An object that cleans up on its own can hand that back to its own maid so it is never destroyed twice:

local maid = Maid.new()
maid:GiveTask(JestUtils.afterThis(maid))

Keywords