joshwcomeau / guppy

🐠A friendly application manager and task runner for React.js
ISC License
3.27k stars 154 forks source link

Test create project service (Improve coverage) #373

Closed AWolf81 closed 5 years ago

AWolf81 commented 5 years ago

Summary: Added tests for project creation service.

codecov[bot] commented 5 years ago

Codecov Report

Merging #373 into master will increase coverage by 0.87%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #373      +/-   ##
==========================================
+ Coverage   57.27%   58.14%   +0.87%     
==========================================
  Files         158      158              
  Lines        3314     3314              
  Branches      459      459              
==========================================
+ Hits         1898     1927      +29     
+ Misses       1207     1184      -23     
+ Partials      209      203       -6
Impacted Files Coverage Δ
src/services/create-project.service.js 95.55% <100%> (+64.44%) :arrow_up:
AWolf81 commented 5 years ago

Thanks for the changes.

Why is a change of let DISABLE=false not possible? Is it because it's creating a new reference for every new value? Maybe I have to play with this a bit in a Codesandbox. With the object literal it is working because the reference to DISABLE constant will be the same for every modification of the literal, right? function(...args) is more readable and OK to use.

I have one point I'd like to know what you think - see inline comment that I added. After that I think it can be merged.

superhawk610 commented 5 years ago

Yeah, booleans are passed by value while objects are passed by reference. Here's a quick demo:

let bool = false;
let obj = { prop: false };

function mutateByValue(a) {
  // a is a copy of the passed value, so mutations aren't persisted outside this block scope
  a = true;
}

function mutateByReference(a) {
  // a is a reference to the passed value, so mutations modify the original object directly
  // changes are persisted outside this block scope
  a.prop = true;
}

mutateByValue(bool);
console.log(bool); // false

mutateByReference(obj);
console.log(obj.prop); // true