Skip to content

Commit

Permalink
add use walkTokens tests
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed May 13, 2020
1 parent a337c76 commit 267a176
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/unit/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ describe('use extension', () => {
expect(html).toBe('<p>extension</p>\n');
});

it('should use walkTokens', () => {
let walked = 0;
const extension = {
walkTokens(token) {
walked++;
}
};
marked.use(extension);
marked('text');
expect(walked).toBe(2);
});

it('should use options from extension', () => {
const extension = {
headerIds: false
Expand All @@ -141,6 +153,29 @@ describe('use extension', () => {
expect(html).toBe('<h1>heading</h1>\n');
});

it('should call all walkTokens in reverse order', () => {
let walkedOnce = 0;
let walkedTwice = 0;
const extension1 = {
walkTokens(token) {
if (token.walkedOnce) {
walkedTwice++;
}
}
};
const extension2 = {
walkTokens(token) {
walkedOnce++;
token.walkedOnce = true;
}
};
marked.use(extension1);
marked.use(extension2);
marked('text');
expect(walkedOnce).toBe(2);
expect(walkedTwice).toBe(2);
});

it('should use last extension function and not override others', () => {
const extension1 = {
renderer: {
Expand Down

0 comments on commit 267a176

Please sign in to comment.