Skip to content

Commit

Permalink
fix: configureFonts should be deterministic (callstack#4095)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-fournier authored Oct 12, 2023
1 parent 2bb6256 commit 557ba69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/styles/__tests__/fonts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,20 @@ describe('configureFonts', () => {
},
});
});

it('should be deterministic', () => {
// first call that should not mutate the original config
configureFonts({
config: {
labelMedium: {
color: 'coral',
},
},
});

// second call that should return the original config without modification
const fontsB = configureFonts({ config: {} });

expect(fontsB.labelMedium.color).toBeUndefined();
});
});
1 change: 1 addition & 0 deletions src/styles/fonts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function configureV3Fonts(
}

return Object.assign(
{},
typescale,
...Object.entries(config).map(([variantName, variantProperties]) => ({
[variantName]: {
Expand Down

0 comments on commit 557ba69

Please sign in to comment.