Can not find line break setting after opening curly brace in resharper - resharper

When I create a new javascript constructor I want to do this:
var PersonViewModel = function(){};
Then I press return after the semicolon and get this:
var PersonViewModel = function()
{
};
But what I want is this:
var PersonViewModel = function()
{
// so I can immediately continue writing code here
};
I want that line break after the opening curly brace.
I can not find the settings in the javascript options, anyone knows please?

ReSharper tries very hard not to mess with user typing (at least when it is correct). It can help you not to touch very much, but if you want to type something fully, it tries to allow you to do it. But the feature that you want breaks this principle: when user would type to function statement side-by-side, the second one would be inside the first one instead.
What I suggest instead is just typing ...function(){ and pressing Enter. ReSharper would add } for you automatically, so you can just continue to write function body. You would get syntactically correct code, because ; could be omitted in JavaScript. ReSharper would highlight missing ; anyway and would suggest to add all missing ; in the whole file. Just use this feature from time to time to make your code beautiful.

Related

How to fix or ignore the following prettier error

What exactly is this prettier error?:
error Insert '·' prettier/prettier
Does it expect a space after () in?:
beforeEach(function() {
What's the way to ignore that in eslint/prettier?
Insert ·eslintprettier/prettier is an error which you will get if you haven't given proper spacing. Here it denotes space by .
In your case, the prettier formatter expects you to give space in the function and () inside the beforeEach(). So changing your code from -
beforeEach(function() {
to
beforeEach(function () {
would solve the issue.
Note: In most text editors, you have the option to format on save by which you can set the text editor to automatically format the code as per the default formatted so that you won't need to worry about solving these issues. Once you save the document, your code will get auto-formatted.
Also, you can ignore if you don't want to format as per the change suggested. For eg. In VSCode, you will get options if you hover over the error -
You can choose to fix the problem, disable it for the line or even for entire file.
Prettier expects a space before the functions' (), i.e., between the word function and the opening parenthesis:
beforeEach(function () {
// Here -------^

nightwatch - check for popup window, after each click event

Is there a way in nightwatch to check whether a popup window appears after each click event?
I have a problem that randomly an error message appear and I don't want to write for each click event the same callback function.
I have already tried out the after and afterEach commands in the Global.js but then the commands will only run after the whole test suite.
I also have tried it local within a test file, although it also does not cover all single click events, even though the official website writes "... while beforeEach and afterEach are ran before and after each testcase (test step)"?
Solution I'm looking for:
.waitForElementVisible('selector')
.click('selector')
.click('selector')
Solution I have come up with so far:
.waitForElementVisible('selector')
.click('selector', isPresent)
.click('selector', isPresent)
isPresent as a callback function, which does the checking and close the popup window if it appears.
Is there another way to write a function (with or without after and/or forEach), so that it will be called after each click event or after each command. Thus, I don't have to write the isPresent repetitive code?
You can insert something like this in your page object file:
var popupCommand = {
popupCheck:function(){
return this.waitForElementVisible('selector', 5000)
.click('selector', isPresent)
.click('selector', isPresent)
},
module.exports = {
commands:[popupCommand],
elements:{
firstElement: {selector: 'xpath',locateStrategy: 'xpath'},
secondElement: {selector: 'css'},
}
}
Where 'popupCommand' will be the name of your page object file, for example 'Popup'. And also you will have to insert your isPresent callback function here so you can use it.
I did my best to explain you as much as possible what and how to do that :)
you should yse .switchWindow() method.
Why don't you write your own custom command specific for that case, so that way you will avoid repetitive code?

SVG fill animation cycle broken

i am looking to simply animate two fill colors of an SVG. ping pong, loop, however you want to call it. the pieces work on their own, but put together into a recursive function to form the loop breaks it.
here's what i have (using jQuery):
$(document).ready( function() {
var items = $('.st1');
items.css('fill', '#ff3600');
bl-colorCycle();
function bl-colorCycle() {
console.log('color cycle called');
items.animate({fill: '#00ffcc'}, 5000, 'linear', bl-colorCycle);
}
});
for some reason, this throws this error:
SyntaxError: missing ( before formal parameters
what the heck am i missing? i've torn this apart several times and for the life of me, i cannot spot where the hell the missing '(' is! i've read all that i can find here, and found nothing that helps in this scenario. i've even tried putting the function call at the very end, just to see if some weird web-voodoo was at play...bupkiss. :(
i'm hoping someone out there has sharper eyes... :P
TIA.
WR!
Hyphen ("-") is not a legal identifier character. Try underscore ("_") instead. Ie. bl_colorCycle().

Terminating each() block in Protractor

I was automating the an application (using Protractor) and I have come across situation where I wanted to select the an option from the type ahead using the DOWN arrow button from the Keyboard. Here is how I am approaching to this action.
After typing part into the text field I am getting the reference of each option that appear in the type ahead.
Now, I am using .each() method of protractor to iterate through each of the option to look for the required option.
I'm making the script to hit DOWN arrow button to iterate through each option in the type ahead.
Suppose there are 10 options displayed in the type ahead and the option that I need to select is at 5th position. Now when I reach the 5th position I am selecting the option but each() function still continues.
I want the loop to terminate when required option is selected. Something like BREAK statement in FOR loops.
BTW I have tried the above scenario with FOR loop but unable to use BREAK statement within then() handler.
Please let me know how to cope up with this situation.
You could throw an exception to terminate the loop. Put the loop inside try and use catch to wrangle your results. You can also just use a boolean variable to indicate that you have found a match and ignore everything after that point. I would just use a for loop though.
Edit:
You could add a variable to hold an action before the allBenchmarks.each
var action
Then inside the test
if(dataValue == optionToSelect){
action = function() {benchmark.click(); ...}
}
After the loop exits call the action
if (action) action()

Where to initialize extension related data

am a newbie, trying to write some basics extension. For my extension to work i need to initialize some data, so what I did is inside my background.js i declared something like this.
localStorage["frequency"] = 1; //I want one as Default value. This line is not inside any method, its just the first line of the file background.js
Users can goto Options page and change this above variable to any value using the GUI. As soon as the user changes it in UI am updating that value.
Now the problem is to my understanding background.js reloads everytime the machine is restarted. So every time I restart my machine and open Chrome the frequency value is changed back to 1. In order to avoid this where I need to initialize this value?
You could just use a specific default key. So if frequency is not set you would try default-frequency. The default keys are then still set or defined in the background.js.
I like to do that in one step, in a function like this
function storageGet(key,defaultValue){
var item = localstorage.getItem(key);
if(item === null)return defaultValue;
else return item;
}
(According to the specification localstorage must return null if no value has been set.)
So for your case it would look something like
var f = storageGet("frequency",1);
Furthermore you might be interested in checking out the chrome.storage API. It's used similar to localstorage but provides additional functionalities which might be useful for your extension. In particular it supports to synchronize the user data across different chrome browsers.
edit I changed the if statement in regard to apsillers objection. But since the specification says it's ought to be null, I think it makes sense to check for that instead of undefined.
This is another solution:
// background.js
initializeDefaultValues();
function initializeDefaultValues() {
if (localStorage.getItem('default_values_initialized')) {
return;
}
// set default values for your variable here
localStorage.setItem('frequency', 1);
localStorage.setItem('default_values_initialized', true);
}
I think the problem lies with your syntax. To get and set your localStorage values try using this:
// to set
localStorage.setItem("frequency", 1);
// to get
localStorage.getItem("frequency");

Resources