-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: setup jest for unit testing (#11)
* test: add test for utilities * fix: `transformCount() range * fix: update `transformPixelsToNumber()` regex to include negative values * test: change test description * chore: add test.yml for automation * fix(test.yml): install deps before test
- Loading branch information
1 parent
fed1c69
commit eb707d4
Showing
7 changed files
with
9,907 additions
and
8,617 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
- run: yarn | ||
- run: yarn test |
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,7 @@ | ||
module.exports = { | ||
presets: [ | ||
'@babel/preset-env', | ||
'@babel/preset-react', | ||
'@babel/preset-typescript', | ||
], | ||
} |
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,7 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
transform: { | ||
'^.+\\.(ts|tsx)?$': 'ts-jest', | ||
'^.+\\.(js|jsx)$': 'babel-jest', | ||
}, | ||
} |
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,37 @@ | ||
import { | ||
getRandomInt, | ||
getRandomCount, | ||
transformCount, | ||
transformPixelsToNumber, | ||
} from './utils' | ||
|
||
test('getRandomInt() returns integers between the given range', () => { | ||
let randomInt: number = getRandomInt(0, 10) | ||
expect(randomInt).toBeGreaterThanOrEqual(0) | ||
expect(randomInt).toBeLessThanOrEqual(10) | ||
}) | ||
|
||
test('getRandomCount() returns an array of random integers between 0 and 25', () => { | ||
let randomCount: number[] = getRandomCount(5) | ||
expect(randomCount.length).toBe(5) | ||
randomCount.forEach((count) => { | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
expect(count).toBeLessThanOrEqual(25) | ||
}) | ||
}) | ||
|
||
test('transformCount() returns the correct number of squares', () => { | ||
expect(transformCount(0)).toBe(0) | ||
expect(transformCount(10)).toBe(1) | ||
expect(transformCount(15)).toBe(2) | ||
expect(transformCount(20)).toBe(3) | ||
expect(transformCount(25)).toBe(4) | ||
}) | ||
|
||
test('transformPixelsToNumber() extracts the correct number (without unit)', () => { | ||
expect(transformPixelsToNumber('0px')).toBe(0) | ||
expect(transformPixelsToNumber('10rem')).toBe(10) | ||
expect(transformPixelsToNumber('15em')).toBe(15) | ||
expect(transformPixelsToNumber('-20px')).toBe(-20) | ||
expect(transformPixelsToNumber('2520240394039304px')).toBe(2520240394039304) | ||
}) |
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
Oops, something went wrong.
eb707d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: