Skip to content

Commit

Permalink
fwf
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 3, 2024
1 parent af99af2 commit 0a94c17
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
32 changes: 15 additions & 17 deletions tests/build-docs/convertDocPosts.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const { convertDocPosts } = require('../../scripts/build-docs');
const { docObject, emptyDocObject, singlePostDocObject, nestedChildrenDocObject, } = require('../fixtures/convertDocPostData');
const {
docObject,
emptyDocObject,
singlePostDocObject,
nestedChildrenDocObject
} = require('../fixtures/convertDocPostData');

describe('convertDocPosts', () => {
it('should convert a doc object to an array', () => {
Expand Down Expand Up @@ -31,34 +36,27 @@ describe('convertDocPosts', () => {
});

it('should throw an error if docObject is undefined', () => {
let error;

try {
convertDocPosts(undefined);
} catch (err) {
error = err;
expect(err.message).toContain('Error in convertDocPosts:');
}
expect(error).toBeDefined();
});

it('should throw an error if docObject is a function', () => {
try {
convertDocPosts(() => { });
} catch (err) {
expect(err.message).toContain('Error in convertDocPosts:');
}
});
it('should throw an error if docObject is null', () => {
let error;

it('should throw an error if docObject is a number', () => {
try {
convertDocPosts(123);
convertDocPosts(null);
} catch (err) {
error = err;
expect(err.message).toContain('Error in convertDocPosts:');
}
expect(error).toBeDefined();
});

it('should throw an error if docObject is an array', () => {
try {
convertDocPosts([]);
} catch (err) {
expect(err.message).toContain('Error in convertDocPosts:');
}
});
});
43 changes: 21 additions & 22 deletions tests/fixtures/convertDocPostData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ const docObject = {
},
};

const emptyDocObject = {};

const singlePostDocObject = { item: { title: 'Single Post', slug: '/single' } };

const nestedChildrenDocObject = {
item: { title: 'Root', slug: '/root' },
children: {
child1: {
item: { title: 'Child 1', slug: '/child1' },
children: {
grandchild1: { item: { title: 'Grandchild 1', slug: '/grandchild1' } },
},
const emptyDocObject = {};

const singlePostDocObject = { item: { title: 'Single Post', slug: '/single' } };

const nestedChildrenDocObject = {
item: { title: 'Root', slug: '/root' },
children: {
child1: {
item: { title: 'Child 1', slug: '/child1' },
children: {
grandchild1: { item: { title: 'Grandchild 1', slug: '/grandchild1' } },
},
child2: { item: { title: 'Child 2', slug: '/child2' } },
},
};

module.exports = {
docObject,
emptyDocObject,
singlePostDocObject,
nestedChildrenDocObject,
};

child2: { item: { title: 'Child 2', slug: '/child2' } },
},
};

module.exports = {
docObject,
emptyDocObject,
singlePostDocObject,
nestedChildrenDocObject
};

0 comments on commit 0a94c17

Please sign in to comment.