Skip to content

Commit fd9ddba

Browse files
authored
Merge pull request #32 from rob2d/feature/add-unit-testing
add unit testing
2 parents 37a49ef + 5c31cdd commit fd9ddba

File tree

7 files changed

+7883
-1784
lines changed

7 files changed

+7883
-1784
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
media
3-
build
3+
build
4+
coverage

README.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,18 @@ If passed an `options.hasher` function, this will be used to calculate a hash th
100100
import useViewportSizes from 'use-viewport-sizes';
101101

102102
function getBreakpointHash({ vpW, vpH }) {
103-
if(vpW < 640) {
104-
return 'md';
105-
}
106-
if(vpW < 320) {
107-
return 'sm';
108-
}
109-
else if(vpW < 240) {
110-
return 'xs';
111-
}
112-
else {
113-
return 'lg';
114-
}
103+
if(vpW <= 240) { return 'xs' }
104+
if(vpW <= 320) { return 'sm' }
105+
else if(vpW <= 640) { return 'md' }
106+
else return 'lg';
115107
}
116108

117109
function MyBreakpointBehaviorComponent() {
118-
const [vpW, vpH, bp] = useViewportSizes({ hasher: getBreakpointHash });
110+
const [vpW, vpH] = useViewportSizes({ hasher: getBreakpointHash });
119111

120-
// do-something-with-breakpoints in render
121-
// and add new update for vpW, vpH in this component's
122-
// subtree only when a named breakpoint changes
112+
// do-something in render and add new update for vpW,
113+
// vpH in this component's subtree only when a breakpoint
114+
// hash updates
123115
}
124116
```
125117

babel.config.testing.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react"
5+
],
6+
"plugins": [
7+
"@babel/plugin-transform-runtime"
8+
]
9+
};

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// jest.config.js
2+
module.exports = {
3+
transform: {
4+
'\\.js$': ['babel-jest', { configFile: './babel.config.testing.js' }]
5+
},
6+
testEnvironment: "jsdom"
7+
};

0 commit comments

Comments
 (0)