mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-05 21:03:09 +00:00
Add tests for blocks from plugins
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
var should = require('should');
|
||||
|
||||
module.exports = {
|
||||
blocks: {
|
||||
// Simple test
|
||||
hello: function(blk) {
|
||||
return 'Hello ' + blk.body + '!';
|
||||
},
|
||||
|
||||
// Test using the conetxt "this"
|
||||
testContext: function(s) {
|
||||
this.should.have.property('config');
|
||||
this.should.have.property('log');
|
||||
this.should.have.property('options');
|
||||
this.should.have.property('resolve').which.is.a.function;
|
||||
this.should.have.property('book').which.equal(this);
|
||||
|
||||
return 'Hello ' + s + '!';
|
||||
}
|
||||
}
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "gitbook-plugin-test-blocks",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"gitbook": "*"
|
||||
}
|
||||
}
|
||||
+26
-2
@@ -138,8 +138,7 @@ describe('Plugins', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should list all resources for website', function() {
|
||||
it('should list all filters', function() {
|
||||
_.size(filters).should.equal(2);
|
||||
});
|
||||
|
||||
@@ -151,5 +150,30 @@ describe('Plugins', function() {
|
||||
filters.testContext('Hello');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Blocks', function() {
|
||||
var plugin, blocks;
|
||||
|
||||
before(function() {
|
||||
plugin = new BookPlugin(book, 'test-blocks');
|
||||
return plugin.load(PLUGINS_ROOT)
|
||||
|
||||
.then(function() {
|
||||
blocks = plugin.getBlocks();
|
||||
});
|
||||
});
|
||||
|
||||
it('should list all blocks', function() {
|
||||
_.size(blocks).should.equal(2);
|
||||
});
|
||||
|
||||
it('should correctly normalize block', function() {
|
||||
blocks.hello.exec({ body: 'World' }).should.equal('Hello World!');
|
||||
});
|
||||
|
||||
it('should correctly set contexts for filter', function() {
|
||||
blocks.testContext.exec({ body: 'Hello' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user