pivotal-legacy / pivotal_ide_prefs

CLI for installing and tracking your IDE preferences over time.
76 stars 68 forks source link

What's the deal with javascript testing live templates ? #77

Closed tjarratt closed 3 years ago

tjarratt commented 6 years ago

So, out of the box, the pivotal_ide_prefs installs some nice live templates that look like this

// type "it" and hit tab in intelli-j
it("should _____", function() {

});

In a lot of modern projects with es6 and newer language features, we'll often update our live templates so they look like this:

// type "it" and hit tab in intelli-j
it("should _____", () => {

});

(we do this mostly because our default eslint rules enforce using arrow functions instead of the old-school function keyword)

What would people think about updating the live templates ? I wouldn't want to keep both versions around, but I'm not sure how harmful changing this template could be (does anyone really need to use the function version ???).

moonmaster9000 commented 6 years ago

I think the general recommendation is to continue to use function() functions, instead of arrow functions: https://github.com/jasmine/jasmine/issues/1416, unless you really know what you're doing, and what you're gaining/losing by switching to arrow functions...

On Fri, May 4, 2018 at 9:15 AM, Tim Jarratt notifications@github.com wrote:

So, out of the box, the pivotal_ide_prefs installs some nice live templates that look like this

// type "it" and hit tab in intelli-jit("should _____", function() {

});

In a lot of modern projects with es6 and newer language features, we'll often update our live templates so they look like this:

// type "it" and hit tab in intelli-jit("should _____", () => {

});

(we do this mostly because our default eslint rules enforce using arrow functions instead of the old-school function keyword)

What would people think about updating the live templates ? I wouldn't want to keep both versions around, but I'm not sure how harmful changing this template could be (does anyone really need to use the function version ???).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pivotal-legacy/pivotal_ide_prefs/issues/77, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHm0gUn_r83u724nw_wtLV6gUROXND1ks5tvFRbgaJpZM4TyoWB .

-- Parker

tjarratt commented 6 years ago

That's pretty interesting - although that seems like an edge case that's lightyears away from most of the code I've seen on Vanilla js, Angular and React projects between our London and Paris offices.

My understanding (albeit limited) is that arrow functions behave in a way that's simpler to understand, and that it reduces some of the complexity of managing the scope that is present in js.

I'll see if I can find out how many people are using function() {} versus () => {} in their jasmine specs...

atomanyih commented 6 years ago

in my experience, it's become convention in es6 for arrow functions to be the "default" when you're defining an anonymous function.

airbnb's javascript styleguide recommends arrow functions for anonymous functions google's javascript styleguide prefers arrow functions over function by default

these are two of the most dominant javascript styleguides right now and many projects use their associated eslint configurations rather than defining their own

for my part, I always change the live templates to use arrow functions


it may also be worth noting that many projects are moving away from using jasmine as a testing framework. compare responses to the stateofjs survey from 2017, 2016, and 2018

Jasmine usage ( used it before, would use it again ) 2016: 41% 2017: 38% 2018: 29%

Jasmine interest ( heard of it, would like to learn ) 2016: 26% 2017: 24% 2018: 25%

Jasmine awareness ( percentage of respondents who had heard of jasmine ) 2016: 90% 2017: 87% 2018: 86%

AFAIK, no current projects in our office (SF labs) are using jasmine

edit: frontend tooling survey results show similar results
edit: added 2018 results