Ember qunit tests are being called twice - qunit

I recently upgraded my "ember-cli" to "2.10.0" and "ember-cli-qunit" to "3.0.1" but each test module is getting run twice. However when I try the code in jsbin I am unable to recreate the issue. My test looks like:
import Qunit from 'qunit';
Qunit.module("[Reporting]", function (hooks) {
hooks.before(function () {
console.log("before");
});
hooks.after(function () {
console.log("after");
});
Qunit.test("test 1", function (assert) {
console.log("test 1");
assert.equal(1,1);
});
Qunit.test("test 2", function (assert) {
console.log("test 2");
assert.equal(1,1);
});
}
I can see that my quint version is 2.1.1 and jquery version is 1.11.3.
My Index.html file looks like this;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Studio Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for 'head'}}
{{content-for 'test-head'}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/studio-blessed1.css">
<link rel="stylesheet" href="assets/studio.css">
<link rel="stylesheet" href="assets/test-support.css">
<style>#blanket-main { position: relative; z-index: 99999; }</style>
{{content-for 'head-footer'}}
{{content-for 'test-head-footer'}}
</head>
<body>
{{content-for 'body'}}
{{content-for 'test-body'}}
<script src="assets/vendor.js"></script>
<script src="assets/test-support.js"></script>
<script src="assets/studio.js"></script>
<script src="assets/blanket-options.js"></script>
<script src="assets/blanket-loader.js"></script>
<script src="testem.js"></script>
<script src="assets/tests.js"></script>
{{content-for 'body-footer'}}
{{content-for 'test-body-footer'}}
</body>
</html>

I found the issue with my test. I was trying to configure the set of tests that would loaded based on a query parameter I send when running the tests. The way I was trying to do that basically wrong.
In my test-helper.js, I had added :
import Resolver from 'studio/resolver';
import {setResolver} from 'ember-qunit';
import TestLoader from 'ember-cli-test-loader/test-support';
setResolver(Resolver.create());
//ADDED THIS PROTOTYPE AS PER MENTIONED IN https://github.com/ember-cli/ember-cli-test-loader
TestLoader.prototype.shouldLoadModule = function(moduleName) {
//return (moduleName.match(/[-_]test$/));
var additionalCondition = true;
var dirName = QUnit.urlParams.directory;
if (dirName) {
additionalCondition = moduleName.indexOf(dirName + '/') === 0 && (moduleName.indexOf('/', dirName.length + 1) === -1);
}
return additionalCondition;
};
TestLoader.load();
But instead I had to do:
import Ember from 'ember';
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
import TestLoader from 'ember-cli-test-loader/test-support';
Ember.$(document).ready(function () {
TestLoader.prototype.shouldLoadModule = function (moduleName) {
//return (moduleName.match(/[-_]test$/));
var additionalCondition = true;
var dirName = QUnit.urlParams.directory;
if (dirName) {
additionalCondition = moduleName.indexOf(dirName + '/') === 0 && (moduleName.indexOf('/', dirName.length + 1) === -1);
}
return additionalCondition;
};
});
setResolver(resolver);
But now I am getting following error when calling andThen helper method:
Assertion after the final `assert.async` was resolved
So:
//THIS FAILS(BUT USED TO WORK BEFORE QUINT UPGRADE)
test("DUMMY TEST 2", function (assert) {
clickSomeElement();
andThen(()=> {
assert.equal(1, 1);
});
});
I am using really classic version of ember "1.10.1". Not sure if it was caused by it! Could use some help resolving it. Posted here too: https://github.com/ember-cli/ember-cli/issues/6293

Related

How to restrict the user not to enter characters in the summernote textarea?

I'm using summernote component and what I want to do is I want to stop the user from adding characters if the text area is pre filled, but I couldn't figure out how to stop typing event. I tried this and it worked for me
$(document).ready(function() {
$('#summernote').summernote({
callbacks: {
onKeydown: function(e) {
if(e.keyCode > 64)
{
e.target.blur();
}
}
}
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Summernote Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/summernote#0.8.18/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote#0.8.18/dist/summernote.min.js"></script>
</head>
<body>
<div class="container mt-3">
<div class="inner-container">
<div id="summernote1">
Hello Summernote ! please enter text.
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#summernote1').summernote({
callbacks: {
onKeydown: function(e) {
if(e.keyCode > 0)
{
e.preventDefault();
}
}
}
});
});
</script>
</body>
</html>
I simply added this code in my html page and it worked for me.
$(document).ready(function() {
$('#summernote1').summernote({
callbacks: {
onKeydown: function(e) {
if(e.keyCode > 0)
{
e.preventDefault();
}
}
}
});
});

i use open sever and when i use jquery, displays error 500 (Internal Server Error). How to fix it?

i want to sent data in controller laravel, using jquery and ajax. But when i click on button, displays this error
here is my code ajax
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function ()
{
$("#b").bind("click",function ()
{
var id = "888";
$.ajax({
url:"/insert_",
mehtod:"get",
data:{
id:id
}
});
});
});
here is my html code
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="js/jquery.js"></script>
<script src="js/f.js"></script>
</head>
<body>
<button id="b">do it</button>
</body>
</html>
here is my controller code
public function data(Request $request)
{
$student = $request->input('id');
DB::table("student_table")
->where("name","=",$student)->delete();
}
here is my web.php code
Route::get('/insert_',"StudentController#data");
I think that the query in the controller is wrong because you are passing the id but then you are using it to retrieve the student's name...
In my opinion, you should change this code
...
$student = $request->input('id');
DB::table("student_table")
->where("name","=",$student)->delete();
...
to
...
$student = $request->input('id');
DB::table("student_table")
->where("id","=",$student)->delete();
...
The problem is that if the student is not found then is not possible to call the delete method. I hope that this answer could help.

CLDR/Globalize: slice JSON array: Uncaught TypeError: Cannot read property '0' of undefined

We are trying to use cldr/globalize;
an exception is triggered while loading 13 CLDR' json files (like likelySubtags.json).
It seems that the size of the 'arguments' is 14 (instead of 13) which triggers the exception "Uncaught TypeError: Cannot read property '0' of undefined"
They are several examples using the same 'JavaScript' code and it doesn't seem that people complain; see A, B, C, D and E
Do you need further info? Do you need more code? Just let me know
JavaScript, load cldr data, set locale to 'en'
$(document).ready(function () {
// https://stackoverflow.com/questions/35863853/using-jquery-globalize-with-mvc-5
// download json files on https://github.com/unicode-cldr?page=2
// how to setup globalize, cldr and json data: http://johnnyreilly.github.io/globalize-so-what-cha-want
var locale = 'en'; // TODO: manage the localization based on user preferences (browser)
// https://stackoverflow.com/questions/32586551/what-is-the-best-way-to-handle-validation-with-different-culture
$.when(
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/likelySubtags.json"),
$.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/numbers.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/numberingSystems.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/plurals.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/ordinals.json"),
$.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/currencies.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/currencyData.json"),
$.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/ca-gregorian.json"),
$.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/timeZoneNames.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/timeData.json"),
$.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/weekData.json"),
$.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/dateFields.json"),
$.getJSON("/Scripts/plugins/cldr-units-full-30.0.2/main/" + locale + "/units.json"),
console.log("JSONs loaded")
).then(function () {
console.log("start slicing");
return [].slice.apply(arguments, [0]).map(function (result) {
console.log("slicing done");
return result[0];
});
}).then(Globalize.load).then(function () {
Globalize.locale(locale);
console.log("Locale set to " + locale);
}).then(console.log("LOADED EVERYTHING"));
});
HTML , load the javascripts
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>StratEx | Project management</title>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css">
<link href="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet">
<link href="/Content/font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="/Content/bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet">
<link href="/Content/animate.css" rel="stylesheet">
<link href="/Content/style.css" rel="stylesheet">
<link href="/Content/themes/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet">
<script type="application/javascript" async="" defer="" src="https://by2.uservoice.com/t2/ID/web/ID/track.js?_=TIMESTAMP&s=1&c=__uvSessionData0&d=HASH"></script>
<script type="text/javascript" async="" src="//widget.uservoice.com/CODE.js"></script><script async="" src="//www.google-analytics.com/analytics.js"></script>
<script
src="/Scripts/jquery-2.2.1.js"></script>
<script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr.js"></script>
<script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/event.js"></script>
<script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/supplemental.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/number.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/plural.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/message.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/currency.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/date.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/relative-time.js"></script>
<script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/unit.js"></script>
<script src="/Scripts/plugins/jquery-validation-1.15.1/dist/jquery.validate.js"></script>
<script src="/Scripts/plugins/jquery-validation-unobtrusive-3.2.6/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/plugins/jquery-ajax-unobtrusive-3.2.4/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/plugins/jquery-validation-globalize-1.0.0/jquery.validate.globalize.js"></script>
<script src="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.js"></script>
<script src="/Content/bootstrap-3.3.7/js/bootstrap.js"></script>
</head>
There is an extra console.log("JSONs loaded") which triggers the exception as a 14th item is included inside 'arguments'

how to disable previous months in kendo month picker

I have a kendo date picker in which only months are shown.Now i want to disable previous months of current month to disable so user will not be able to enter previous month.
Please try with the below code snippet.
<!DOCTYPE html>
<html>
<head>
<title>Jayesh Goyani</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.mobile.all.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/kendo.all.min.js"></script>
</head>
<body>
<div id="date"></div>
<script>
$(document).ready(function () {
var myDatePicker = $("#date").kendoDatePicker().data("kendoDatePicker");
myDatePicker.min(new Date()); //This code line will hide previous date from date picker
});
</script>
</body>
</html>
Update 1:
<!DOCTYPE html>
<html>
<head>
<title>Jayesh Goyani</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.1111/styles/kendo.mobile.all.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.1111/js/kendo.all.min.js"></script>
<style>
.disabledDay {
display: block;
overflow: hidden;
min-height: 22px;
line-height: 22px;
padding: 0 .45em 0 .1em;
cursor: default;
opacity: 0.5;
}
</style>
</head>
<body>
<input id="datepicker" style="width: 150px;" />
<script>
disabledDaysBefore = [
+new Date("10/20/2015")
];
$(document).ready(function () {
var p = $("#datepicker").kendoDatePicker({
value: new Date(),
dates: disabledDaysBefore,
change: onChange,
month: {
content: '# if (data.date < data.dates) { #' +
'<div class="disabledDay">#= data.value #</div>' +
'# } else { #' +
'#= data.value #' +
'# } #'
},
open: function (e) {
$(".disabledDay").parent().removeClass("k-link")
$(".disabledDay").parent().removeAttr("href")
},
}).data("kendoDatePicker");
});
function onChange() {
var tillDate = new Date(disabledDaysBefore[0]);
var selectedDate = new Date(kendo.toString(this.value(), 'd'));
if (tillDate > selectedDate) {
tillDate = tillDate + parseInt(1);
$("#datepicker").data("kendoDatePicker").value(tillDate);
}
}
</script>
</body>
</html>
Let me know if any concern.
You can use the disableDates property and specify a function to check the date is before the current date, roughly along these lines:
$("#monthpicker").kendoDatePicker({
start: "year",
depth: "year",
format: "MMMM yyyy",
disableDates: function (date) {
var currentDate = new Date();
if (date.getFullYear() <= currentDate.getFullYear() && date.getMonth() < currentDate.getMonth()) {
return true;
} else {
return false;
}
}
});

Unable to load data from JSON

I want to load json data from js file (url:'myTurorials.json' throwing error so I used .js,)
Please give me solution, thanks in advance.
code from 'myTurorials.js' file is as bellow
`[
{"display": "JavaScript Tutorial", "url":"http://www.w3schools.com/js/default.asp"},
{"display": "HTML Tutorial", "url":"http://www.w3schools.com/html/default.asp"},
{"display": "CSS Tutorial", "url": "http://www.w3schools.com/css/default.asp"}
]`
code from 'myTurorials.js' ends here
$(document).ready(function(){
$.ajax({
type : 'GET',
url : 'myTutorials.js',
dataType : 'json',
contentType : 'application/json',
success: function (response) {
alert('success');
},
error : function(){
alert('error');
},
complete : function(){
//init();
}
});
});
function init(){
myFunction(myArray);
}
function myFunction(arr) {
var out = "";
var i;
for(i = 0; i < arr.length; i++) {
out += '' + arr[i].display + '<br>';
}
document.getElementById("id01").innerHTML = out;
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>HTML5 responsive website tutorial</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans|Baumans' rel='stylesheet' type='text/css'/>
<script>
</script>
<style>
</style>
<!-- my files -->
<script src="jquery.js"></script>
<script src="main.js"></script>
</head>
<body>
<div id="id01"></div>
</body>
</html>

Resources