init.js:196 Uncaught TypeError: Cannot read property 'positions' of null - modal-dialog

I have a modal which triggers on page load for first time viewers, however, when you hit the close button, the video keeps playing and looking at my error block, this is the only error I get:
init.js:196 Uncaught TypeError: Cannot read property 'positions' of null
and here is the lines it is screaming about:
function openContent(_target, _direction) {
if (!isDesktop()) return;
var _element = document.querySelector(_target);
$(_target).css(_element.positions).css({
"z-index": 2
}).animate(_element.destinations, "easeOutQuint", function () {
$(_target).addClass('active')
});
$('header').animate(_element.headerDestinations, "easeOutQuint");
}
function closeContent(_direction) {
var _target = 'section.active';
var _element = document.querySelector(_target);
$(_target).removeClass('active').delay(300).animate(_element.positions, "easeOutQuint", function () {
$(this).css({
"z-index": -99999
})
});
$('header').delay(300).animate(_element.headerOrigins, "easeOutQuint");
}
function isDesktop() {
if ($(window).width() >= 768) return true;
else return false;
}
Here is the specific line in question and in beween the --><-- is where the inspector is pointing:
$(_target).removeClass('active').delay(300).animate(*-->_element<--*.positions, "easeOutQuint", function () {
I am pretty new to JS, so please forgive me.
Thanks

Related

ChangeStream#destroy is not a method?

I got this error:
app:tail-mongodb ERROR Unhandled rejection:
z.cs.destroy is not a function
TypeError: z.cs.destroy is not a function
at createChangeStream
(/Users/Olegzandr/codes/interos/read-from-mongodb/dist/main.js:74:18)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
here is my code:
import {ChangeStream} from "mongodb";
const z = {
cs: null as ChangeStream,
};
const createChangeStream = () => {
if (z.cs) {
z.cs.removeAllListeners();
z.cs.destroy();
}
const changeStream = z.cs = d.db(dbName).collection(dbCollName).watch();
changeStream.on('change', next => {
if (!(next && next.fullDocument)) {
log.warn('changed doc did not have fullDocument property, or was undefined:', next);
}
bun.handleIn(next.fullDocument || next);
});
};
seems weird that destroy() is not a valid method on the ChangeStream. Does anyone know the proper way to close a ChangeStream? The TypeScript typings say that this method is available, but I guess it is not.

How to break out of each loop in protractor?

I have to automate a scenario where a user has to assign one group/row out of n(10) group/row on 1st page.
All groups/rows cannot be assigned.Only those group/row can be assigned that does not throw error message(based on group review state) in banner.
So we have to iterate over each group and check if error appears or not. If no error is there then assign the group/row and break the .each loop.
The code below works fine but at the end it throws the following error:
Failed: unknown error: Element is not clickable at point (333, 555).
Other element would receive the click: <div class="loading"></div"
As per the error script is trying to click checkboxOfAllGroupRow element even after loop is over.
How can we fix this issue?
this.assignGroupRow = function () {
pageTab.click();
filterDropdownIcon.click();
setValuesInFilterDropDown.click()
.then(function () {
functionLibrary.waitForLoaderToDisappear();
browser.sleep(3000);
var num = -1;
checkboxOfAllGroupRow.each(function (checkbox, index) {
checkbox.click().then(function () {
assignButtonInGroupPage.click();
dismissableErrorMessageInBanner.isPresent()
.then(function (errorPresence) {
if (errorPresence) {
checkbox.click();
dismissableErrorCloseIconInBanner.click();
if (index == groupCountOnFirstPage - 1)
console.log(" No groups in first page can be assigned.");
} else {
assignReasonIcon.click();
youIdentifiedSMEReason.click();
suggestSMENameTextField.click();
suggestSMENameInputField.sendKeys("ldapID");
functionLibrary.waitElementToBeVisisble(highlightedOptionInSuggestSMEDropDown);
highlightedOptionInSuggestSMEDropDown.click();
yesBtnInAssignmentOfGroupDialog.click()
.then(function () {
bannerMessageOnAssignmentOfGroup.getText().then(function (message) {
expect(message).toContain('group selected successfully assigned');
num = index;
return;
});
console.log(errorPresence + ' inside else. dialog is present at ' + index);
});
}
});
});
});
});
}

Protractor : Cannot read property 'then' of undefined when resolving a promise

I'm new to Protractor and writing some sample test cases.So while trying to get the text of an element, I'm not able to resolve my custom promise.When i try to print it says Cannot read property 'then' of undefined . Here's is what i'm trying to do.
let temp = "u";
var another = function (para) {
var obj, size = 0;
let version;
var promise;
let text_1;
element.all(by.xpath('//td[#class="ellipsis"]/span[#class="ng-binding ng-isolate-scope"]'))
.each(function (element, index) {
element.getText()
.then(function (text) {
size++;
version = element.all(by.xpath("//td/span[#class='ng-binding']"));
text_1 = text;
if (para == text_1) {
version.get(size - 1).getText().then(function (temp) {
console.log("done->" + temp);
//promise= Promise.resolve(temp);
promise = new Promise((resolve, reject) => resolve(version.get(size - 1).getText()));
console.log(promise);
});
};
});
});
return promise;
};
describe('testing', function () {
it('testing', function () {
browser.get('http://localhost:8090/xxxxxxxx');
var para = "aa ";
protractor.promise.controlFlow().execute(function () {
another(para).then(function (t) {
console.log("success->" + t)
});
});
});
});
The output is as follows:
Failed: Cannot read property 'then' of undefined
Because you init the var promise in nested then of element.all().each(), which is executed async. When another(para) execute complete, its return value promise still undefined. Next execute Undefined.then(), that's why you get error: Cannot read property 'then' of undefined
Change below code lines in function another as following:
// return element.all().then() as the function return value
return element.all(by.xpath('//td[#class="ellipsis"]/span[#class="ng-binding ng-isolate-scope"]'))
.each(function (element, index) {
element.getText()
.then(function (text) {
size++;
version = element.all(by.xpath("//td/span[#class='ng-binding']"));
text_1 = text;
if (para == text_1) {
version.get(size - 1).getText().then(function (temp) {
console.log("done->" + temp);
//promise= Promise.resolve(temp);
promise = new Promise((resolve, reject) => resolve(version.get(size - 1).getText()));
console.log(promise);
});
};
});
})
.then(function(){
return promise; // return the promise in element.all().then()
});

Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object

This is my code
/******************************************************/
import Ember from "ember";
var TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function(){
// Get the todo title by the "New Todo" input
var title = this.get('newTitle');
if(!title.trim()){ return; }
// Create the new Todo model
var todo = this.store.createRecord('todo', {
title: title,
isCompleted: false
});
// Clear the 'New Todo' input field
this.set('newTitle', '');
// Save the new model
todo.save();
},
clearCompleted: function(){
var completed = this.filterBy('isCompleted', true);
completed.invoke('deleteRecord');
completed.invoke('save');
}
},
remaining: function() {
return this.filterBy('isCompleted', false).get('length');
}.property('#each.isCompleted'),
inflection: function() {
var remaining = this.get('remaining');
return remaining === 1 ? 'todo' : 'todos';
}.property('remaining'),
hasCompleted: function(){
return this.get('completed') > 0;
}.property('completed'),
completed: function(){
return this.filterBy('isCompleted', true).get('length');
}.property('#each.isCompleted'),
allAreDone: function(key, value) {
if(value === undefined){
return !!this.get('length') && this.everyProperty('isCompleted', true);
} else {
this.setEach('isCompleted', value);
this.invoke('save');
return value;
}
}.property('#each.isCompleted')
});
export default TodosController;
/*******************************************************/
In terminal not showing any error when i run this command
$ ember server
but in browser not showing any thing and console showing this error
Uncaught Error: Assertion Failed: ArrayProxy expects an Array or
Ember.ArrayProxy, but you passed object
Please suggest me what i m doing wrong, the code is also on github : https://github.com/narayand4/emberjs
thanks in advance.
The most likely reason for this is that you have a controller which extends from Ember.ArrayController while you only return a plain object in the corresponding model.
I had the same issue and changed my controller to extend Ember.Controller instead.
In the related route for this controller, your model method doesn't return an array, as you've indicated by extending an arrayController.

for loop not waiting for function to end

I have 5 links on a page and i have to check if all are links are working or not. Here is the code
// iterate through each link and check if ti works.
for(var i=0; i < 5; i++) {
var ifLinkWorks = verifyLinkWorks(links[i]);
if(ifLinkWorks){ OK }
else{ error }
}
This is verifyLinkWorks function. It opens a link. After it get opened, it checks if the page is loaded properly
function verifyLinkWorks(link) {
return winjs.Promise(function(complete) {
link.click();
// wait for page to load
return winjs.promise.timeout(4000).then(function () {
// check if page is loaded
var islinkOK = IsPageLoaded();
complete(islinkOK); // i want verifyLinkWorks to return this value
});
});
}
After reaching link.click(), it is not waiting for page to load. Instead it jumps to the if condtion in outer for loop (which makes linkWorks = undefined therefore,gives Error). How to make it wait in the verfifyLinkWorks function.
Thanks in advance...
You'll need to wait for the results of each promise, either all at once, or individually. As the actions are all async in nature, the code can't wait, but it can call a function when it completes all of the work.
Here, I've created an array which will hold each Promise instance. Once the loop has completed, the code waits for all to complete, and then using the array that is passed, checking the result at each index.
// iterate through each link and check if it works.
var verifyPromises = [];
for(var i=0; i < 5; i++) {
verifyPromises.push(verifyLinkWorks(links[i]));
}
WinJS.Promise.join(verifyPromise).done(function(results) {
for(var i=0; i < 5; i++) {
var ifLinkWorks = results[i];
if (ifLinkWorks) { /* OK */ }
else { /* error */ }
}
});
In case the link.click() call fails, I've wrapped it in a try/catch block:
function verifyLinkWorks(link) {
return WinJS.Promise(function(complete, error) {
try {
link.click();
} catch (e) {
complete(false); // or call the error callback ...
}
// wait for page to load, just wait .. no need to return anything
WinJS.Promise.timeout(4000).then(function () {
// check if page is loaded
var islinkOK = IsPageLoaded();
// finally, call the outer promise callback, complete
complete(islinkOK);
});
});
}
If you want to check the validity of a URL, I'd suggest you consider using WinJS.xhr method to perform a HEAD request instead (rfc). With each link variable, you can use a timeout to validate that there's a reasonable response at the URL, without downloading the full page (or switch to a GET and check the response body).
WinJS.Promise.timeout(4000,
WinJS.xhr({
type: 'HEAD',
url: link
}).then(function complete(result) {
var headers = result.getAllResponseHeaders();
}, function error(err) {
if (err['name'] === 'Canceled') {
}
if (err.statusText) {
}
})
);
Ok heres the link to the msdn code sample for win js promise object.
Promise winjs
now going through the code
<button id="start">StartAsync</button>
<div id="result" style="background-color: blue"></div>
<script type="text/javascript">
WinJS.Application.onready = function (ev) {
document.getElementById("start").addEventListener("click", onClicked, false);
};
function onClicked() {
addAsync(3, 4).then(
function complete(res) {
document.getElementById("result").textContent = "Complete";
},
function error(res) {
document.getElementById("result").textContent = "Error";
},
function progress(res) {
document.getElementById("result").textContent = "Progress";
})
}
function addAsync(l, r) {
return new WinJS.Promise(function (comp, err, prog) {
setTimeout(function () {
try {
var sum = l + r;
var i;
for (i = 1; i < 100; i++) {
prog(i);
}
comp(sum);
}
catch (e) {
err(e);
}
}, 1000);
});
}
</script>
you will see the addAsync(3,4).then() function. So all the code is to be kept inside that function in order to have a delayed response . Sorry m using a tab so cannot write it properly.
Also go through link then for winjs promise