-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from jaredwray/adding-in-hooks-for-render,-sa…
…ve-to-file,-and-load-from-file Adding in hooks for render and renderSync
- Loading branch information
Showing
3 changed files
with
120 additions
and
26 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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
import { | ||
test, describe, expect, | ||
} from 'vitest'; | ||
import {Writr, WritrHooks} from '../src/writr.js'; | ||
|
||
describe('Writr Render Hooks', async () => { | ||
test('it should change the content before rendering', async () => { | ||
const writr = new Writr('Hello, World!'); | ||
writr.onHook(WritrHooks.beforeRender, data => { | ||
data.body = 'Hello, Universe!'; | ||
}); | ||
const result = await writr.render(); | ||
expect(result).toBe('<p>Hello, Universe!</p>'); | ||
}); | ||
|
||
test('it should change the content before rendering sync', () => { | ||
const writr = new Writr('Hello, World!'); | ||
writr.onHook(WritrHooks.beforeRender, data => { | ||
data.body = 'Hello, Sync!'; | ||
}); | ||
const result = writr.renderSync(); | ||
expect(result).toBe('<p>Hello, Sync!</p>'); | ||
}); | ||
}); |