Skip to content

Commit

Permalink
Delete duplicate test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Dec 12, 2019
1 parent 90e9d5f commit 2e65f2e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 84 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>

<body>
<script src="src/use-layout.js"></script>
<script src="src/use-state.js"></script>
</body>

</html>
31 changes: 31 additions & 0 deletions demo/src/state-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { h, render, useState } from '../../src'

function Counter() {
const [up, setUp] = useState(0)
const [down, setDown] = useState(0)
return (
<div class="counter">
<h1>{up}</h1>
<button onClick={() => setUp(up + 1)}>+</button>
<h1>{down}</h1>
<button onClick={() => setDown(down - 1)}>-</button>
<Count count={up} />
</div>
)
}

function Count(props) {
const [add, setAdd] = useState(0)
const [cut, setCut] = useState(0)
return (
<div class="counter">
<h2>{props.count}</h2>
<h1>{add}</h1>
<button onClick={() => setAdd(add + 1)}>+</button>
<h1>{cut}</h1>
<button onClick={() => setCut(cut - 1)}>-</button>
</div>
)
}

render(<Counter />, document.body)
31 changes: 6 additions & 25 deletions demo/src/use-state.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import { h, render, useState } from '../../src'
import { h, render, useState, useLayout, useEffect } from '../../src'

function Counter() {
const [up, setUp] = useState(0)
const [down, setDown] = useState(0)
function App() {
const [count, setCount] = useState(0)
return (
<div class="counter">
<h1>{up}</h1>
<button onClick={() => setUp(up + 1)}>+</button>
<h1>{down}</h1>
<button onClick={() => setDown(down - 1)}>-</button>
<Count count={up} />
<div>
<button onClick={() => setCount(count + 1)}>{count}</button>
</div>
)
}

function Count(props) {
const [add, setAdd] = useState(0)
const [cut, setCut] = useState(0)
return (
<div class="counter">
<h2>{props.count}</h2>
<h1>{add}</h1>
<button onClick={() => setAdd(add + 1)}>+</button>
<h1>{cut}</h1>
<button onClick={() => setCut(cut - 1)}>-</button>
</div>
)
}

render(<Counter />, document.body)
render(<App />, document.body)
7 changes: 3 additions & 4 deletions demo/src/with-context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, useState, useEffect, render } from '../../src'
import { h, useState, useEffect, render, useCallback } from '../../src'

// import { render, createElement as h } from 'preact/compat'
// import { useState, useEffect } from 'preact/hooks'
Expand Down Expand Up @@ -33,9 +33,8 @@ const useTheme = withContext('light')

function App() {
const [theme, setTheme] = useTheme()
const setMemoTheme = useCallback(() =>
setTheme(theme === 'dark' ? 'light' : 'dark')
)
const setMemoTheme = setTheme(theme === 'dark' ? 'light' : 'dark')

return (
<div>
{theme}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"module": "dist/fre-esm.js",
"scripts": {
"test": "jest --coverage",
"test-key":"jest ./test/reconcilation.test.js",
"build": "rollup -c && gzip-size dist/fre.js",
"format": "prettier --write \"{src,test,demo}/**/*.js\""
},
Expand Down
54 changes: 0 additions & 54 deletions test/update.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,6 @@ test('async state update', async () => {
])
})

test('persist reference to any value', async () => {
const Component = () => {
const ref = useRef('')

ref.current = ref.current + 'x'

return <p>{ref.current}</p>
}

const content = <Component />

await testUpdates([
{
content,
test: ([p]) => {
expect(p.textContent).toBe('x')
}
},
{
content,
test: ([p]) => {
expect(p.textContent).toBe('x')
}
}
])
})

test('persist reference to any value', async () => {
const Component = () => {
const ref = useRef('')

ref.current = ref.current + 'x'

return <p>{ref.current}</p>
}

const content = <Component />

await testUpdates([
{
content,
test: ([p]) => {
expect(p.textContent).toBe('x')
}
},
{
content,
test: ([p]) => {
expect(p.textContent).toBe('x')
}
}
])
})

test('render/update object properties and DOM attributes', async () => {
let lastChildren = []

Expand Down

0 comments on commit 2e65f2e

Please sign in to comment.