-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a0a421
commit a9f532c
Showing
3 changed files
with
30 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 28 additions & 4 deletions
32
sources/@roots/bud-framework/test/methods/after/after.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
import {type Bud, factory} from '@repo/test-kit' | ||
import {beforeEach, describe, expect, it} from 'vitest' | ||
import {beforeAll, describe, expect, it, vi} from 'vitest' | ||
|
||
import {after as subject} from '../../../src/methods/after/index.js' | ||
|
||
describe(`bud.after`, function () { | ||
let after: subject | ||
let bud: Bud | ||
|
||
beforeEach(async () => { | ||
beforeAll(async () => { | ||
bud = await factory() | ||
after = subject.bind(bud) | ||
}) | ||
|
||
it(`is a function`, () => { | ||
it(`should be a function`, () => { | ||
expect(after).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`returns Bud`, async () => { | ||
it(`should return bud`, async () => { | ||
const value = after(async () => {}) | ||
expect(value).toBe(bud) | ||
}) | ||
|
||
it(`should call the callback`, async () => { | ||
const fn = vi.fn(async () => null) | ||
after(fn) | ||
await bud.hooks.fire(`compiler.done`, bud, {}) | ||
expect(fn).toHaveBeenCalled() | ||
}) | ||
|
||
it(`should work with a synchronous callback`, async () => { | ||
const fn = vi.fn() | ||
after(fn) | ||
await bud.hooks.fire(`compiler.done`, bud, {}) | ||
expect(fn).toHaveBeenCalled() | ||
}) | ||
|
||
it(`should call the error handler if supplied`, async () => { | ||
const onError = vi.fn() | ||
after(() => { | ||
throw new Error(`test`) | ||
}, onError) | ||
await bud.hooks.fire(`compiler.done`, bud, {}) | ||
|
||
expect(onError).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters