Skip to content

Instantly share code, notes, and snippets.

@leesei
Last active August 6, 2018 07:42
Show Gist options
  • Save leesei/6bdad2b7b70d250c1d76582bda9d318a to your computer and use it in GitHub Desktop.
Save leesei/6bdad2b7b70d250c1d76582bda9d318a to your computer and use it in GitHub Desktop.
hexo/test/scripts/hexo/tag_errors.js
'use strict';
var sinon = require('sinon');
describe.only('Tag Errors', () => {
var Hexo = require('../../../lib/hexo');
var hexo = new Hexo(__dirname);
before(() => {
hexo.init().then(() => {
hexo.extend.tag.register('test', function(args, content){
return '<code>' + content + '</code>';
}, {ends: true});
};
});
it('tag error - unknown tag', () => {
const errorCallback = sinon.spy(err => {
err.should.have.property('message', 'Unexpected tag "abc" on line 1.');
});
const body = [
'{% abc %}',
' content',
'{% endabc %}',
].join('\n');
hexo.render.render({
text: body,
engine: 'swig'
})
.then(result => {
console.log(result);
})
.catch (err => {
console.log(err);
errorCallback(err);
// throw err;
});
// try {
// var result = hexo.render.renderSync({
// text,
// });
// } catch (err) {
// errorCallback(err);
// }
errorCallback.calledOnce.should.be.true;
});
it('tag error - no closing tag', () => {
const errorCallback = sinon.spy(err => {
console.log(err.message);
// err.should.have.property('message', '');
});
const text = [
'{% test %}',
' content',
].join('\n');
try {
hexo.render.renderSync({
text,
engine: 'swig'
});
} catch (err) {
errorCallback(err);
}
errorCallback.calledOnce.should.be.true;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment