Я пытался получить доступ к своему файлу входа в систему. js из моего файла login-spe c. js, чтобы я мог протестировать некоторые методы в in. Однако я продолжаю получать эту ошибку:
PS C:\Project\Personal\OddsNEnds> npm test
> oddsnends@0.0.0 test C:\Project\Personal\OddsNEnds
> jasmine
C:\Project\Personal\OddsNEnds\public\javascripts\login.js:1
$(document).ready(function(){
^
ReferenceError: $ is not defined
at Object.<anonymous> (C:\Project\Personal\OddsNEnds\public\javascripts\login.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Project\Personal\OddsNEnds\spec\login-Spec.js:1:13)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
npm ERR! Test failed. See above for more details.
Не знаю, почему это происходит, вот мои файлы: Логин. js
$(document).ready(function(){
$("#nextButton").click(checkInputs)
$("#submitButton").click(checkInputs)
})
checkInputs = function(){
let password = $('#passwordInput').val()
let email = $('#emailAddress').val();
if($('#passwordInput').prop('disabled')){
if(email.includes("@")){
ShowPasswordInput()
} else{
NoAtError()
}
} else{
basicCheckOfCredentials(email, password);
}
}
ShowPasswordInput = function(){
$('#emailAddress').prop("readonly", true)
$('#emailAddress').addClass("form-control-plaintext")
$('#emailAddress').removeClass("form-control")
$('#emailAddress').css('color','white')
$('#password').css('display', 'block')
$('#passwordInput').prop('disabled',false)
$('#nextButton').prop("value","Submit")
}
updateSpinner = function (){
$('#login').addClass("spinner-border")
$('#login').removeClass("login")
$('#login').html("")
}
basicCheckOfCredentials = function(email, password){
try{
checkEmail(email)
checkPassword(password)
updateSpinner()
SendCredentialsToApi(email,password)
} catch(err){
if(err.message.includes('email')){
NoAtError()
} else if (err.message.includes('Password')){
passwordError()
} else {
console.log(err)
}
}
}
checkEmail = function (email){
if(!email.includes('@')){
throw new Error("Not a valid Email, there was no @ Symbol")
}
}
checkPassword = function(password){
if(password.length < 8){
throw new Error("Password was not long enough, must be 8 characters long")
}
}
NoAtError = function(){
$('#emailAddress').removeClass("emailError")
$('#emailAddress').popover("toggle")
$('#emailAddress').css("border", "5px solid")
$('#emailAddress').css("border-color", "transparent")
$('#emailAddress').addClass("emailError")
}
passwordError = function(){
$('#passwordInput').popover("toggle")
}
SendCredentialsToApi = function(email, password){
window.location.assign('/home');
}
login-spe c . js
var login = require('../public/javascripts/login')
login.e js
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="/stylesheets/loginStyles.css">
<link href="https://fonts.googleapis.com/css?family=Fredoka+One&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<title>Login</title>
</head>
<body>
<div class="logoArea">
<h1 class="logo fade-in">OddsNEnds</h1>
</div>
<div class="page fade-in-rest">
<div class="login" id="login">
<div class="form-group " id="email">
<label for="emailAddress">Email address</label>
<input type="email" class="form-control" id="emailAddress" aria-describedby="emailHelp" data-toggle="popover" data-trigger="focus" data-content="This is not a valid email, there is no @ symbol">
<small id="emailHelp" class="form-text">We'll never share your email with anyone else.</small>
</div>
<div class="form-group" id="password">
<label for="passwordInput">Password</label>
<input type="password" disabled class="form-control" id="passwordInput" data-toggle="popover" data-trigger="focus" data-content="The password given is not atleast 8 Characters long">
</div>
<input type="button" value="Next" id="nextButton" class="btn btn-outline-light"/>
</div>
</div>
<script type="text/javascript" src="/javascripts/login.js"></script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
Мне сказали, что мне нужно использовать экспорт, однако у меня есть Я получаю ошибки, когда использую это тоже. Внизу логина. js
exports.basicCheckOfCredentials = basicCheckOfCredentials;
exports.checkEmail = checkEmail;
exports.checkPassword = checkPassword;
Однако я получаю эту ошибку:
ReferenceError: exports is not defined
Я полностью потерян, так что любой помощь была бы отличной!