Is there a flag to allow braceless If statements in JSHINT?
ie:
if (true) return false;
I've looked through the docs, but didn't find anything...
Never mind, found the solution:
curly: false
http://www.jshint.com/docs/options/#curly
Related
Hello People does anyone know how to implement Webdriverio's waitUntil (explicit wait) to see if an element is existing?
to check if an element is existing we have the following:
browser.waitForExist(selector, timeout)
which after timeout will return a true of false depending upon if the element existed in the dom.
By that logic:
browser.waitUntil( function(){
return browser.waitForExist(selector) == 'true')
},timeout,'element failed to exist')
should work right?
I have the below code to identify whether an element exist or not using waitUntil in wdio.
browser.waitUntil(function(){
return browser.elements(NAVIGATION_ICONS).value.length > 0;
}, 15000, 'The navigation icon are not there');
The variable NAVIGATION_ICONS is an xpath.
Hope this helps.
Thank you,
Naveen.
I would use isExisting()
browser.waitUntil( function(){
return selector.isExisting())
},timeout,'element failed to exist')
I want to create a Mock with a method that should return true for a specific argument, and false for any other argument.
I can achieve this with:
$this->myMock = Mockery::mock(MyClass::class);
$this->myMock->shouldReceive('myMethod')->with('my-argument')->andReturn(true);
$this->myMock->shouldReceive('myMethod')->andReturn(false);
But I was wondering if there's any shorter way to specify this, as I have to do this for many mocks, and looks like a lot of code for this simple purpose (note my properties/classes/methods/arguments names are quite longer than this example).
You can use Mockery's andReturnUsing-method. It takes a closure to calculate the return value by evaluating the provided argument. Should work like:
$this->mock
->shouldReceive('myMethod')
->andReturnUsing(function ($argument) {
if ($argument) {
return true;
}
return false;
});
I discovered I can use:
$this->myMock = Mockery::mock(MyClass::class);
$this->myMock->shouldReceive('myMethod')->passthru();
This will defer the calls to myMethod() to the real object, which will return true or false depending on the argument - this obviously doesn't do the same thing the code in the question does, but it does work in my scenario and it's quite shorter.
I'm using dhtmlxGrid and as I've found in the docs (https://docs.dhtmlx.com/api__dhtmlxgrid_oneditcell_event.html) returning "true" confirms the edit, while a value (for example newValue) sets the value.
I've tried both methods, but neither of them works! I can't confirm the edit by "true" nor set the value by "newValue".
Here is my code:
myGrid.attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){
doOnEdit(stage,rId,cInd,nValue,oValue)
});
...
function doOnEdit(stage,rId,cInd,nValue,oValue){
if (cInd==0 && nValue=="100")
return false
return true
}
Can anybody explain my mistake or is there a bug?
Please, try to use the following solution:
myGrid.attachEvent("onEditCell", doOnEdit);
...
function doOnEdit(stage,rId,cInd,nValue,oValue){
if (cInd==0 && nValue=="100")
return false
return true
}
My docs each have a nested array with an _id field, which is required. This triggers the "duplicate Id in..." console warning. Pretty sure it's related to: https://github.com/meteor/meteor/issues/1980
Unfortunately, with about 50,000 docs being passed through (local data analysis, not a production app) all the console activity is starting to slow me down.
Is there a parameter to pass in to squelch console warnings or just a quick & dirty workaround? Nothing fancy/stable required.
You can do console.warn = function () {} to disable all warnings. But this will suppress all warnings, not just that particular warning, so that's not ideal.
If you look at the ObserveSequence source, you can see the code which does the warnings:
var warn = function () {
if (ObserveSequence._suppressWarnings) {
ObserveSequence._suppressWarnings--;
} else {
if (typeof console !== 'undefined' && console.warn)
console.warn.apply(console, arguments);
ObserveSequence._loggedWarnings++;
}
};
So setting Package["observe-sequence"].ObserveSequence._suppressWarnings to a large number will prevent that many warnings from ObserveSequence.
So I'm trying to figure out a way to get a value from the browser when a test is running with DalekJS. As far as I can tell, it's not currently possible. I even had a look at hacking the Dalek code, but since I know very, very little about CommonJS and NodeJS other than installing and running things, I figured I might actually ask around first.
What I'm trying to do is something like:
// Non-working example
module.exports = {
'My Test': function(test) {
var foo;
test
.open('http://localhost/mysite')
.execute(function(){
foo = document.getElementById('bar');
})
.type('#myField', foo)
.done();
}
}
Now I know why this code doesn't work: because the execute() function is executed in the context of the browser window (as though I was typing it into the console).
The question I'm asking is: is there a way I can retrieve a value to use in my test?
Context information: My use case is that I'm testing an E2E scenario where a form is submitted and a code is provided to the user. This code then needs to be entered on another page. I could potentially set up mock values for the purpose of testing, but then it's not a true scenario.
Thanks in advance!
Yes,
that is a usecase we haven't implemented yet, but until we haven't found a proper solution, you can use a workaround:
module.exports = {
'My Test': function(test) {
test
.open('http://localhost/mysite')
.execute(function(){
var foo = document.getElementById('bar').innerText;
document.getElementById('myField').setAttribute('value', foo);
})
.done();
}
};
This method has some problems, none of the eventhandlers like keyup, keydown etc. will be fired when adding the value to the field in this way.
If your code doesn't rely on them, you are good to go.
Else you would have to wait some weeks until the new version is out, which will provide a better solution for such scenarios.
Hope that helps.
Cheers
Sebastian
Based on the documented example of the .log.message function, you can do something like the following:
module.exports = {
'My Test': function(test) {
test
.open('http://localhost/mysite')
.execute(function(){
var foo = document.getElementById('bar').value;
this.data('foo', foo);
})
.type('#myField', test.data('foo'))
.done();
}
}