OSDN Git Service

debug relating with asynchronous code
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Sat, 23 Jan 2016 03:17:36 +0000 (12:17 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Sat, 23 Jan 2016 03:17:36 +0000 (12:17 +0900)
server/class/DB.js
test/mocha/DB.test.js

index 590e9f7..c7d2811 100644 (file)
@@ -11,6 +11,7 @@ function DB() {
     var co = require('co');
 
     var sequelize;
+    var test = 'hello';
 
     var dbOption = {
         dialect: 'sqlite'
@@ -24,10 +25,15 @@ function DB() {
                     name: 'root',
                     parent: ''
                 };
-                return Directory.insert(root);
+                return Directory.create(root);
             })
             .then(function() {
-                return {};
+                var c = {
+                    sayHello: function() {
+                        return test;
+                    }
+                };
+                resolve(c);
             });
         });
     }
index 6a96fee..15805c7 100644 (file)
@@ -4,19 +4,17 @@
     var expect = require('chai').expect;
 
     //process.env['NODE_ENV'] = 'production';
-    describe('DB クラス', function() {
-        var db;
-        var test;
-        before(function(done) {
-            var promise = new DB();
-            promise.then(function(r) {
-                db = r;
-                done();
-            });
+    var db;
+    before(function() {
+        return DB()
+        .then(function(r) {
+            db = r;
         });
-        it('test of test', function(done) {
-            db.sayHello();
-            done();
+    });
+
+    describe('DB クラス', function() {
+        it('test of test', function() {
+            expect(db.sayHello()).to.equal('hello');
         });
     });
 })();