Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test verifying altered order won't trigger config changes #1075

Merged
merged 3 commits into from
Jul 16, 2017

Conversation

robertohuertasm
Copy link
Member

Related to #1072.

If we introduce the proposed change then order alterations will trigger change detection. That's why intersectionWith was being used. I've added the test so we won't miss this next time.

@codecov
Copy link

codecov bot commented Jul 16, 2017

Codecov Report

Merging #1075 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1075   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          48      48           
  Lines        2256    2264    +8     
  Branches      109     109           
======================================
+ Hits         2256    2264    +8
Impacted Files Coverage Δ
test/init/applyCustomizationsManager.test.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32923dc...a121f29. Read the comment docs.

const newConfig = { ...userConfig, associations: { ...userConfig.associations } };
newConfig.associations.files = [...userConfig.associations.files];
newConfig.associations.files.reverse();
const initConfig = JSON.parse(JSON.stringify(newConfig));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is no need to stringify and parse here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I just copied the line like a fool! 😂

newConfig.associations.files = [...userConfig.associations.files];
newConfig.associations.files.reverse();
manageApplyCustomizations(newConfig, userConfig, spy);
expect(spy.called).to.not.be.true;
Copy link
Member

@JimiC JimiC Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature dictates oldConfig, newConfig, fn. You need to revert the order of the first two parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@JimiC
Copy link
Member

JimiC commented Jul 16, 2017

Why do I have the feeling that

 userConfig.associations.files = [
          { icon: "js", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
          { icon: "js2", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
        ];
        const initConfig = { ...userConfig, associations: { ...userConfig.associations } };
        initConfig.associations.files = [...userConfig.associations.files];
        userConfig.associations.files.reverse();

can be written as

userConfig.associations.files = [
          { icon: "js", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
          { icon: "js2", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
        ];
        const newConfig = { ...userConfig };
        newConfig.associations.files.reverse();

or will it reverse also the userConfig.associations.files?

@robertohuertasm
Copy link
Member Author

Yes, it will keep the same references so you cannot do that.

@JimiC
Copy link
Member

JimiC commented Jul 16, 2017

So { ...userConfig } is a ref copy instead of cloning.

@robertohuertasm
Copy link
Member Author

You're right.

@JimiC
Copy link
Member

JimiC commented Jul 16, 2017

I just remembered why I did stringify and parse. It's the vanilla js for cloning.

@robertohuertasm robertohuertasm merged commit 6d49d9a into master Jul 16, 2017
@robertohuertasm
Copy link
Member Author

I also use this for cloning huge objects.

@robertohuertasm robertohuertasm deleted the 1072-missing-test branch July 16, 2017 16:41
@JimiC
Copy link
Member

JimiC commented Jul 16, 2017

So the test can be written as

        userConfig.associations.files = [
          { icon: "js", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
          { icon: "js2", extensions: ["myExt1", "myExt2.custom.js"], format: "svg" },
        ];
        const initConfig = JSON.parse(JSON.stringify(userConfig));
        userConfig.associations.files.reverse();
        manageApplyCustomizations(initConfig, userConfig, spy);

to keep uniformity with the others.

@robertohuertasm
Copy link
Member Author

robertohuertasm commented Jul 16, 2017

I've already added it...

To be honest, I favor the new syntax over the JSON.parse trick. I only clone like this when I really need to clone the whole object which in this case... could make sense 😉 but I stick to the new ways when only having to modify a single property.

I leave it up to you if you want to include the change in #1074.

@JimiC
Copy link
Member

JimiC commented Jul 16, 2017

The thing is that with stringify-parse you achieve the same result with fewer code lines which fall into my coding guidelines (we have already discussed this in another case). I think I'm gonna make the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants