summaryrefslogtreecommitdiffstats
path: root/testing/setup.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-11 13:02:20 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-11 13:02:24 +0200
commitef589a6b133ac67a7904f8bb2cbec42c96dec914 (patch)
treed505c567cd80b0681bbf5f7b46b2a25ed591e28a /testing/setup.js
parentd5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (diff)
downloadgitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.zip
gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.gz
gitbook-ef589a6b133ac67a7904f8bb2cbec42c96dec914.tar.bz2
Switch tests to mocha while keeping jest structure
Diffstat (limited to 'testing/setup.js')
-rw-r--r--testing/setup.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/setup.js b/testing/setup.js
new file mode 100644
index 0000000..b91a299
--- /dev/null
+++ b/testing/setup.js
@@ -0,0 +1,49 @@
+var is = require('is');
+var path = require('path');
+var fs = require('fs');
+var expect = require('expect');
+
+expect.extend({
+ /**
+ Check that a file is created in a directory:
+
+ expect('myFolder').toHaveFile('hello.md');
+ */
+ toHaveFile: function(fileName) {
+ var filePath = path.join(this.actual, fileName);
+ var exists = fs.existsSync(filePath);
+
+ expect.assert(
+ exists,
+ 'expected %s to have file %s',
+ this.actual,
+ fileName
+ );
+ return this;
+ },
+ toNotHaveFile: function(fileName) {
+ var filePath = path.join(this.actual, fileName);
+ var exists = fs.existsSync(filePath);
+
+ expect.assert(
+ !exists,
+ 'expected %s to not have file %s',
+ this.actual,
+ fileName
+ );
+ return this;
+ },
+
+ /**
+ Check that a value is defined (not null nor undefined)
+ */
+ toBeDefined: function() {
+ expect.assert(
+ !(is.undefined(this.actual) || is.null(this.actual)),
+ 'expected to be defined'
+ );
+ return this;
+ }
+});
+
+global.expect = expect;