Skip to content

Commit

Permalink
feat(tag): add unregister() method
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jan 1, 2020
1 parent a9bbc42 commit 5179ccf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/extend/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ class Tag {
this.env.addExtension(name, tag);
}

unregister(name) {
if (!name) throw new TypeError('name is required');

if (this.env.hasExtension(name)) this.env.removeExtension(name);
}

render(str, options, callback) {
if (!callback && typeof options === 'function') {
callback = options;
Expand Down
31 changes: 31 additions & 0 deletions test/scripts/extend/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,37 @@ describe('Tag', () => {
errorCallback.calledOnce.should.be.true;
});

it('unregister()', () => {
const tag = new Tag();

tag.register('test', (args, content) => Promise.resolve(args.join(' ')), {async: true});
tag.unregister('test');

return tag.render('{% test foo bar %}')
.then(result => {
console.log(result);
throw new Error('should return error');
})
.catch(err => {
err.should.have.property('type', 'unknown block tag: test');
});
});

it('unregister() - name is required', () => {
const errorCallback = sinon.spy(err => {
err.should.have.property('message', 'name is required');
});

try {
tag.unregister();
} catch (err) {
errorCallback(err);
}

errorCallback.calledOnce.should.be.true;
});


it('render() - context', () => {
const tag = new Tag();

Expand Down

0 comments on commit 5179ccf

Please sign in to comment.