diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-22 15:39:36 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-22 15:39:36 +0100 |
commit | 0b3bdcb2193e10f5bf0f6959475563d8c430aa40 (patch) | |
tree | 78de15e61b8beaadaefd5f0c48159c5fa4680311 | |
parent | 6653307fda137253cd10d4d4f6d2e010c1c0f604 (diff) | |
download | gitbook-0b3bdcb2193e10f5bf0f6959475563d8c430aa40.zip gitbook-0b3bdcb2193e10f5bf0f6959475563d8c430aa40.tar.gz gitbook-0b3bdcb2193e10f5bf0f6959475563d8c430aa40.tar.bz2 |
Add tests for blocks from plugins
-rw-r--r-- | test/node_modules/gitbook-plugin-test-blocks/index.js | 21 | ||||
-rw-r--r-- | test/node_modules/gitbook-plugin-test-blocks/package.json | 7 | ||||
-rw-r--r-- | test/plugins.js | 28 |
3 files changed, 54 insertions, 2 deletions
diff --git a/test/node_modules/gitbook-plugin-test-blocks/index.js b/test/node_modules/gitbook-plugin-test-blocks/index.js new file mode 100644 index 0000000..7104006 --- /dev/null +++ b/test/node_modules/gitbook-plugin-test-blocks/index.js @@ -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 + '!'; + } + } +}; diff --git a/test/node_modules/gitbook-plugin-test-blocks/package.json b/test/node_modules/gitbook-plugin-test-blocks/package.json new file mode 100644 index 0000000..a756fb5 --- /dev/null +++ b/test/node_modules/gitbook-plugin-test-blocks/package.json @@ -0,0 +1,7 @@ +{ + "name": "gitbook-plugin-test-blocks", + "version": "1.0.0", + "engines": { + "gitbook": "*" + } +}
\ No newline at end of file diff --git a/test/plugins.js b/test/plugins.js index 03bbc26..8207663 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -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' }); + }); + }); }); |