-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for table of contents helper
- Loading branch information
1 parent
ee3329a
commit 4398329
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getNext, getPrev } from '../TableOfContentsHelper'; | ||
|
||
const data = { | ||
'1': { next: '2' }, | ||
'2': { next: '3', prev: '1' }, | ||
'3': { prev: '2' } | ||
}; | ||
|
||
jest.mock('../data/toc-navigation.json', () => data); | ||
|
||
describe('Table of contents helper', () => { | ||
test('generate next correctly', () => { | ||
expect(getNext('1')).toBe('2'); | ||
expect(getNext('2')).toBe('3'); | ||
expect(getNext('3')).toBeUndefined(); | ||
}); | ||
|
||
test('generate prev correctly', () => { | ||
expect(getPrev('1')).toBeUndefined(); | ||
expect(getPrev('2')).toBe('1'); | ||
expect(getPrev('3')).toBe('2'); | ||
}); | ||
|
||
test('handle invalid values correctly', () => { | ||
expect(getNext('invalid')).toBeUndefined(); | ||
expect(getNext('')).toBeUndefined(); | ||
|
||
expect(getPrev('invalid')).toBeUndefined(); | ||
expect(getPrev('')).toBeUndefined(); | ||
}); | ||
}); |