Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use beforeEach hook to improve test suite. #109

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
});

});
Loading