@repobuddy/test
v1.1.0
Published
Your repository buddy for test
Readme
@repobuddy/test
[@repobuddy/test] provides basic test utilities.
You normally would access it through other packages, for example, @repobuddy/vitest.
Install
# npm
npm install -D @repobuddy/test
# yarn
yarn add -D @repobuddy/test
# pnpm
pnpm install -D @repobuddy/test
#rush
rush add -p --dev @repobuddy/testexpect.order
Assert your code executes in the expected order,
backed by AssertOrder from assertron.
installOrder(expect) adds order to your test runner's expect.
expect.order.plan(x) then creates an AssertOrder planned for x steps:
import { installOrder } from '@repobuddy/test'
import { expect, it } from 'vitest'
installOrder(expect)
it('calls the callbacks in order', () => {
const o = expect.order.plan(2)
subject.on('start', () => o.once(1))
subject.on('end', () => o.once(2))
subject.run()
o.end() // throws when the 2 planned steps were not all reached
})plan() without an argument creates an unplanned AssertOrder.
The returned instance carries the whole AssertOrder surface:
once, on, atLeastOnce, exactly, any, onAny, is, not, wait, end, and the rest.
installOrder() does not know about your runner's types, so augment them yourself:
import type { ExpectWithOrder } from '@repobuddy/test'
declare module '@jest/expect' {
interface Expect extends ExpectWithOrder {}
}Using @repobuddy/vitest? It ships @repobuddy/vitest/setup/order,
which installs order and augments vitest's types for you.
