Skip to content

Commit

Permalink
Fix snapshot tests
Browse files Browse the repository at this point in the history
Add empty checks, fix #100
  • Loading branch information
petyosi committed Apr 26, 2020
1 parent 57862ad commit 320a6f6
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
"@types/jest": "^24.0.25",
"@types/lodash": "^4.14.144",
"@types/react": "^16.9.34",
"@types/react-test-renderer": "^16.9.2",
"@types/react-dom": "^16.9.6",
"faker": "^4.1.0",
"husky": "^4.2.5",
"parcel": "^1.12.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-test-renderer": "^16.13.1",
"tsdx": "^0.13.2",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
Expand Down
4 changes: 3 additions & 1 deletion src/VirtuosoScroller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const DefaultScrollContainer: TScrollContainer = ({ className, style, reportScro
theRef.addEventListener('scroll', onScroll, { passive: true })
elRef.current = theRef
} else {
elRef.current!.removeEventListener('scroll', onScroll)
if (elRef.current) {
elRef.current.removeEventListener('scroll', onScroll)
}
}
},
[onScroll]
Expand Down
24 changes: 24 additions & 0 deletions test/Virtuoso.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { GroupedVirtuoso } from '../src'
import { Virtuoso } from '../src/Virtuoso'

test('Test rendering of empty list', () => {
expect(
renderer.create(
<div>
<Virtuoso totalCount={100} item={() => <div />} />
</div>
)
).toMatchSnapshot()
})

test('Test rendering of empty grouped list', () => {
expect(
renderer.create(
<div>
<GroupedVirtuoso groupCounts={[]} group={() => <div />} item={() => <div />} />
</div>
)
).toMatchSnapshot()
})
103 changes: 103 additions & 0 deletions test/__snapshots__/Virtuoso.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test rendering of empty grouped list 1`] = `
<div>
<div
style={
Object {
"WebkitOverflowScrolling": "touch",
"height": "40rem",
"outline": "none",
"overflowY": "auto",
"position": "relative",
}
}
tabIndex={0}
>
<div
style={
Object {
"height": "100%",
"overflow": "absolute",
"position": "absolute",
"top": 0,
"width": "100%",
}
}
>
<div
style={
Object {
"marginTop": "NaNpx",
}
}
>
</div>
</div>
<div
style={
Object {
"height": "0px",
"position": "absolute",
"top": 0,
}
}
>
 
</div>
</div>
</div>
`;

exports[`Test rendering of empty list 1`] = `
<div>
<div
style={
Object {
"WebkitOverflowScrolling": "touch",
"height": "40rem",
"outline": "none",
"overflowY": "auto",
"position": "relative",
}
}
tabIndex={0}
>
<div
style={
Object {
"height": "100%",
"overflow": "absolute",
"position": "absolute",
"top": 0,
"width": "100%",
}
}
>
<div
style={
Object {
"marginTop": "NaNpx",
}
}
>
</div>
</div>
<div
style={
Object {
"height": "0px",
"position": "absolute",
"top": 0,
}
}
>
 
</div>
</div>
</div>
`;
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,13 @@
dependencies:
"@types/react" "*"

"@types/react-test-renderer@^16.9.2":
version "16.9.2"
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.2.tgz#e1c408831e8183e5ad748fdece02214a7c2ab6c5"
integrity sha512-4eJr1JFLIAlWhzDkBCkhrOIWOvOxcCAfQh+jiKg7l/nNZcCIL2MHl2dZhogIFKyHzedVWHaVP1Yydq/Ruu4agw==
dependencies:
"@types/react" "*"

"@types/react@*":
version "16.9.17"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.17.tgz#58f0cc0e9ec2425d1441dd7b623421a867aa253e"
Expand Down Expand Up @@ -6464,6 +6471,21 @@ react-is@^16.8.4:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"
integrity sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q==

react-is@^16.8.6:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-test-renderer@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.13.1.tgz#de25ea358d9012606de51e012d9742e7f0deabc1"
integrity sha512-Sn2VRyOK2YJJldOqoh8Tn/lWQ+ZiKhyZTPtaO0Q6yNj+QDbmRkVFap6pZPy3YQk8DScRDfyqm/KxKYP9gCMRiQ==
dependencies:
object-assign "^4.1.1"
prop-types "^15.6.2"
react-is "^16.8.6"
scheduler "^0.19.1"

react@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
Expand Down

0 comments on commit 320a6f6

Please sign in to comment.