Skip to content

Commit

Permalink
fix: 🐛 reload inaktivt i fejk (kolplattformen#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanObrink authored Feb 23, 2021
1 parent c329283 commit 9fa63e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/fake.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import store from './store'

const { default: init } = jest.requireActual('@skolplattformen/embedded-api')

const wait = (ms) => new Promise((res) => setTimeout(res, ms))

describe('hooks with fake data', () => {
let api
let storage
Expand Down Expand Up @@ -176,16 +178,10 @@ describe('hooks with fake data', () => {
} = renderHook(() => useNotifications(child), { wrapper })

await waitForNextUpdate()
expect(result.current.status).toEqual('loaded')

result.current.reload()
await waitForNextUpdate()

result.current.reload()
result.current.reload()
await waitForNextUpdate()

result.current.reload()
await waitForNextUpdate()
await wait(30)

expect(result.current.status).toEqual('loaded')
})
Expand Down
2 changes: 1 addition & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const hook = <T>(
const dispatch = useDispatch()

const load = (force = false) => {
if (isLoggedIn && state.status !== 'loading' && (force || state.status === 'pending')) {
if (isLoggedIn && state.status !== 'loading' && ((force && !api.isFake) || state.status === 'pending')) {
const extra: ExtraActionProps<T> = {
key,
defaultValue,
Expand Down

0 comments on commit 9fa63e8

Please sign in to comment.