Skip to content

Commit

Permalink
test: use beforeEach hook to improve test suite. (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored Jul 8, 2024
1 parent f088866 commit beaa06c
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ describe('Index generator', () => {
locals;

// Default config
hexo.config.index_generator = {
const default_index_generator = Object.freeze({
per_page: 10,
order_by: '-date'
};
});

beforeEach(() => {
hexo.config.index_generator = {...default_index_generator};
});

before(() => hexo.init().then(() => Post.insert([
{source: 'foo', slug: 'foo', date: 1e8, order: 0},
Expand Down Expand Up @@ -57,8 +61,6 @@ describe('Index generator', () => {
result[1].data.next_link.should.eql('');
result[1].data.__index.should.be.true;

// Restore config
hexo.config.index_generator.per_page = 10;
});

it('pagination disabled', () => {
Expand All @@ -81,8 +83,6 @@ describe('Index generator', () => {
result[0].data.next_link.should.eql('');
result[0].data.__index.should.be.true;

// Restore config
hexo.config.index_generator.per_page = 10;
});

describe('order', () => {
Expand All @@ -109,8 +109,6 @@ describe('Index generator', () => {
result[0].data.posts.eq(1).source.should.eql('baz');
result[0].data.posts.eq(2).source.should.eql('bar');

// Restore config
delete hexo.config.index_generator.order_by;
});

it('custom order - invalid order key', () => {
Expand All @@ -122,8 +120,6 @@ describe('Index generator', () => {
result[0].data.posts.eq(1).source.should.eql('bar');
result[0].data.posts.eq(2).source.should.eql('baz');

// Restore config
delete hexo.config.index_generator.order_by;
});
});

Expand All @@ -137,8 +133,6 @@ describe('Index generator', () => {
result[1].path.should.eql('yo/2/');
result[2].path.should.eql('yo/3/');

// Restore config
hexo.config.index_generator.per_page = 10;
hexo.config.pagination_dir = 'page';
});

});

0 comments on commit beaa06c

Please sign in to comment.