1
无法运行测试,在node.js上使用jasmine-karma。未捕获TypeError:mongoose.model不是函数 - Jasmine
我已经安装了,因果报应,茉莉,browserify,节点和猫鼬和我试图运行我的测试,但我得到的错误“遗漏的类型错误:mongoose.model是不是一个函数” 和” ... user.js的:10 :0" 。
karma.conf.js
// Karma configuration
// Generated on Fri Sep 16 2016 15:23:39 GMT+0200 (Środkowoeuropejski czas letni)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['browserify','jasmine'],
// list of files/patterns to load in the browser
files: [
'test-main.js',
'spec/server/**/*.js',
'server/scripts/auth.js'
],
browserify: {
debug: true,
transform: [ 'brfs' ]
},
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'server/scripts/auth.js': [ 'browserify' ]
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'jasmine-spec-runner'],
jasmineSpecRunnerReporter: {
jasmineCoreDir: 'jasmine-core'
},
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity}) }
authSpec.js
describe("Test auth", function() {
describe("passwordVerification", function() {
var Auth;
beforeEach(function() {
Auth = new auth();
});
it("is password same", function() {
expect(Auth.isAlphaNumeric("asd111")).toBeTruthy();
});
});
});
auth.js
"use strict";
var mongoose = require('mongoose');
var session = require('express-session');
var User = require('../models/user.js');
var Auth = {
//...
isAlphaNumeric(val) {
if (val.match(/^[a-zA-Z0-9]+$/)) {
return true;
}
else {
return false;
}
}
}
module.exports = Auth;
user.js的
'use strict';
var mongoose = require('mongoose');
var UserSchema = mongoose.Schema({
email : String,
password : String,
isFacebookAccount : Boolean
});
UserModel = mongoose.model("Users", UserSchema, "users");
module.exports = UserModel;
你的变化不帮,还是同样的问题。关于模型函数中的三个参数,我从这里得到这个提示http://stackoverflow.com/a/7722490/2510058,它正确地为我的工作 。所以这不是100%的原因 – user2510058
什么是你的猫鼬版本? – abdulbarik
我的猫鼬版本是3.10.5 – user2510058