-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pull library across from POC and add Typescript declarations and Jest test integration
- Loading branch information
1 parent
0d5c606
commit 09c55bc
Showing
4 changed files
with
313 additions
and
35 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,107 @@ | ||
test("adds 1 + 2 to equal 3", () => { | ||
expect(1 + 1).toBe(3); | ||
import ft from '../src/'; | ||
|
||
const setBodyFontSize = value => (document.body.style.fontSize = value); | ||
const removeBodyStyles = () => (document.body.style = {}); | ||
|
||
beforeEach(() => { | ||
setBodyFontSize('16px'); | ||
}); | ||
|
||
test('requires "base font" on <body />', () => { | ||
removeBodyStyles(); | ||
|
||
expect(() => { | ||
ft('padding', [10, 20]); | ||
}).toThrowError('not found'); | ||
}); | ||
|
||
test('requires "base font" of 16px', () => { | ||
setBodyFontSize('10px'); | ||
|
||
expect(() => { | ||
ft('padding', [10, 20]); | ||
}).toThrowError('font-size is not 16px'); | ||
}); | ||
|
||
test('requires "unit" to be defined', () => { | ||
expect(() => { | ||
ft(undefined, [10, 20]); | ||
}).toThrowError('is not defined'); | ||
}); | ||
|
||
test('requires "unit" to be a "string"', () => { | ||
expect(() => { | ||
ft(100, [10, 20]); | ||
}).toThrowError('is not of type "string"'); | ||
}); | ||
|
||
[ | ||
{ reference: 'min', sizes: [undefined, 20] }, | ||
{ reference: 'max', sizes: [10, undefined] }, | ||
].forEach(({ reference, sizes }) => { | ||
test(`requires "${reference}" to be defined`, () => { | ||
expect(() => { | ||
ft('padding', sizes); | ||
}).toThrowError('is not defined'); | ||
}); | ||
}); | ||
|
||
[{ reference: 'min', sizes: ['10', 20] }, { reference: 'max', sizes: [10, '20'] }].forEach( | ||
({ reference, sizes }) => { | ||
test(`requires "${reference}" to be a "number"`, () => { | ||
expect(() => { | ||
ft('padding', sizes); | ||
}).toThrowError('not of type "number"'); | ||
}); | ||
} | ||
); | ||
|
||
[{ reference: 'min', sizes: [10 / 0, 20] }, { reference: 'max', sizes: [10, 20 / 0] }].forEach( | ||
({ reference, sizes }) => { | ||
test(`requires "${reference}" to be "finite"`, () => { | ||
expect(() => { | ||
ft('padding', sizes); | ||
}).toThrowError('is an "infinite" value'); | ||
}); | ||
} | ||
); | ||
|
||
test('should create a single declaration in the correct format', () => { | ||
const result = ft('padding', [10, 20]); | ||
expect(result).toMatch(` | ||
padding: 0.625rem; | ||
@media (min-width: 30rem) { | ||
padding: 2.0833333333333335vw; | ||
} | ||
@media (min-width: 60rem) { | ||
padding: 1.25rem; | ||
} | ||
`); | ||
}); | ||
|
||
test('should create a multi declaration in the correct format', () => { | ||
const result = ft('padding', { top: [10, 20], bottom: [15, 25] }); | ||
expect(result).toMatch(` | ||
padding-top: 0.625rem; | ||
@media (min-width: 30rem) { | ||
padding-top: 2.0833333333333335vw; | ||
} | ||
@media (min-width: 60rem) { | ||
padding-top: 1.25rem; | ||
} | ||
padding-bottom: 0.9375rem; | ||
@media (min-width: 30rem) { | ||
padding-bottom: 3.125vw; | ||
} | ||
@media (min-width: 50rem) { | ||
padding-bottom: 1.5625rem; | ||
} | ||
`); | ||
}); |
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,11 @@ | ||
module.exports = { | ||
printWidth: 100, | ||
tabWidth: 2, | ||
useTabs: false, | ||
semi: true, | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
bracketSpacing: true, | ||
arrowParens: 'avoid', | ||
parser: 'typescript', | ||
}; |
Oops, something went wrong.