新节点并使用sequelize创建连接到MySQL数据库的通用快速应用程序。使用jasmine-node对db连接进行一些单元测试,当我尝试连接sequelize时,我一直在超时。
// Test the MySQL connection
describe("MySQL", function() {
it("is connectable", function(next) {
var mysql = require('mysql');
var dbconfig = require('../config/database');
var connection = mysql.createConnection(dbconfig.connection);
connection.connect(
function(err, db) {
expect(err).toBe(null);
connection.end();
next();
}
);
});
it("is connectable using sequelize", function(next){
var dbconfig = require('../config/database');
var Sequelize = require('sequelize');
var sequelize = new Sequelize(dbconfig.connection.database, dbconfig.connection.user, null,
function(err, db){
expect(err).toBe(null);
sequelize.close();
next();
}
);
});
});
在上面的两个测试中,第一个传递正常,但续集的测试超时。这是我在控制台上得到的内容。
Failures:
1) MySQL is connectable using sequelize
Message:
timeout: timed out after 5000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 6.267 seconds
这是数据库配置文件。
// config/database.js
module.exports = {
'connection': {
'dialect': 'mysql',
'user': 'root',
'password': '',
'host': 'localhost',
'port' : '3306',
'database': 'my_node_db'
}
};