-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from JakeSidSmith/font-size-density
Fix: Clearing the canvas does not reset density related values
- Loading branch information
Showing
7 changed files
with
44 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Canvasimo from '../src'; | ||
import getContextStub from './helpers/get-context-stub'; | ||
|
||
describe('density', () => { | ||
|
||
const element = document.createElement('canvas'); | ||
jest.spyOn(element, 'getContext').mockImplementation(getContextStub); | ||
const instance = new Canvasimo(element); | ||
const ctx = instance.getCurrentContext(); | ||
|
||
it('should explicitly set the font size upon creation', () => { | ||
expect(ctx.font).toBe('normal normal normal 10px sans-serif'); | ||
expect(instance.getFontSize()).toBe(10); | ||
}); | ||
|
||
it('updates font size when changing the density', () => { | ||
instance.setDensity(2); | ||
|
||
expect(ctx.font).toBe('normal normal normal 20px sans-serif'); | ||
expect(instance.getFontSize()).toBe(10); | ||
}); | ||
|
||
it('retains density when the canvas is cleared', () => { | ||
// Fake browser font reset | ||
ctx.font = '10px sans-serif'; | ||
instance.clearCanvas(); | ||
|
||
expect(ctx.font).toBe('normal normal normal 20px sans-serif'); | ||
expect(instance.getFontSize()).toBe(10); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters