Skip to content

Commit

Permalink
test: add unit test for tag() and head()
Browse files Browse the repository at this point in the history
based on 660d93c
  • Loading branch information
hms5232 committed May 3, 2023
1 parent ec5bd75 commit 4b622db
Show file tree
Hide file tree
Showing 4 changed files with 472 additions and 13 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "Facebook comments plugin for Hexo!",
"main": "index.js",
"scripts": {
"test": "yarn run lint",
"lint": "eslint ."
"test": "yarn run lint && yarn run mocha",
"lint": "eslint .",
"mocha": "mocha --exit"
},
"repository": {
"type": "git",
Expand All @@ -29,8 +30,8 @@
},
"homepage": "https://github.com/hms5232/hexo-tag-fb-comments#readme",
"funding": {
"type" : "individual",
"url" : "https://ko-fi.com/hms5232"
"type": "individual",
"url": "https://ko-fi.com/hms5232"
},
"files": [
"*.js"
Expand All @@ -39,7 +40,9 @@
"hexo": ">=5.0.0"
},
"devDependencies": {
"chai": "^4.3.7",
"eslint": "^8.8.0",
"eslint-config-google": "^0.14.0"
"eslint-config-google": "^0.14.0",
"mocha": "^10.2.0"
}
}
18 changes: 18 additions & 0 deletions test/head.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const assert = require('chai').assert; // 使用 chai 的斷言

describe('#fbCommentsHead()', () => {
it('disable', function() {
const head = require('../head')({});

assert.equal(head(), '');
});

it('enable', function() {
const head = require('../head')({appId: 5232, lang: 'zh_TW'});

const result = head();
assert.include(result, '<meta property="fb:app_id" content="5232" />');
assert.include(result, '<div id="fb-root"></div>');
assert.include(result, '<script async defer crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v12.0"></script>');
});
});
25 changes: 25 additions & 0 deletions test/tag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const assert = require('chai').assert; // 使用 chai 的斷言

describe('#fbComments()', () => {
it('disable', function() {
const tag = require('../tag')({});

assert.equal(tag(), '');
});

it('enable', function() {
const tag = require('../tag')({
width: '100%',
numPosts: '7',
orderBy: 'reverse_time',
colorscheme: 'dark',
});

assert.include(tag(), '<div class="fb-comments"');
assert.include(tag(), 'data-width="100%"');
assert.include(tag(), 'data-numposts="7"');
assert.include(tag(), 'data-order-by="reverse_time"');
assert.include(tag(), 'data-colorscheme="dark"');
assert.include(tag(), '></div>');
});
});
Loading

0 comments on commit 4b622db

Please sign in to comment.