Skip to content

Commit

Permalink
test: use beforeEach hook to improve test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Jul 7, 2024
1 parent f8ef61c commit 861ee76
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 861ee76

Please sign in to comment.