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