mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
75 lines
1.3 KiB
JavaScript
75 lines
1.3 KiB
JavaScript
const walk = require('../../src/walk').walk;
|
|
|
|
describe('walk', function() {
|
|
test('flat comments', function() {
|
|
const comments = [{ name: 'Tom' }];
|
|
|
|
function renamer(comment, options) {
|
|
if (options) {
|
|
comment.name = options.name;
|
|
} else {
|
|
comment.name = 'Tim';
|
|
}
|
|
}
|
|
|
|
expect(walk(comments, renamer)).toEqual([{ name: 'Tim' }]);
|
|
|
|
expect(walk(comments, renamer, { name: 'John' })).toEqual([
|
|
{ name: 'John' }
|
|
]);
|
|
});
|
|
|
|
test('nested comments', function() {
|
|
const comments = [
|
|
{
|
|
name: 'Tom',
|
|
members: {
|
|
static: [
|
|
{
|
|
name: 'Billy'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
];
|
|
|
|
function renamer(comment, options) {
|
|
if (options) {
|
|
comment.name = options.name;
|
|
} else {
|
|
comment.name = 'Tim';
|
|
}
|
|
}
|
|
|
|
expect(walk(comments, renamer)).toEqual([
|
|
{
|
|
name: 'Tim',
|
|
members: {
|
|
static: [
|
|
{
|
|
name: 'Tim'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]);
|
|
|
|
expect(
|
|
walk(comments, renamer, {
|
|
name: 'Bob'
|
|
})
|
|
).toEqual([
|
|
{
|
|
name: 'Bob',
|
|
members: {
|
|
static: [
|
|
{
|
|
name: 'Bob'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]);
|
|
});
|
|
});
|