Skip to content

Commit

Permalink
improve basic tests (pmndrs#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad authored Dec 3, 2020
1 parent 32868b6 commit 3503fda
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions tests/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,21 @@ it('uses a read-only derived atom', async () => {
)
}

const { getByText, findByText } = render(
const { getByText } = render(
<Provider>
<Counter />
</Provider>
)

await findByText('count: 0')
await findByText('doubledCount: 0')

await waitFor(() => {
getByText('count: 0')
getByText('doubledCount: 0')
})
fireEvent.click(getByText('button'))
await findByText('count: 1')
await findByText('doubledCount: 2')
await waitFor(() => {
getByText('count: 1')
getByText('doubledCount: 2')
})
})

it('uses a read-write derived atom', async () => {
Expand All @@ -133,18 +136,21 @@ it('uses a read-write derived atom', async () => {
)
}

const { getByText, findByText } = render(
const { getByText } = render(
<Provider>
<Counter />
</Provider>
)

await findByText('count: 0')
await findByText('doubledCount: 0')

await waitFor(() => {
getByText('count: 0')
getByText('doubledCount: 0')
})
fireEvent.click(getByText('button'))
await findByText('count: 2')
await findByText('doubledCount: 4')
await waitFor(() => {
getByText('count: 2')
getByText('doubledCount: 4')
})
})

it('uses a write-only derived atom', async () => {
Expand Down Expand Up @@ -213,27 +219,31 @@ it('only re-renders if value has changed', async () => {
)
}

const { getByText, findByText } = render(
const { getByText } = render(
<Provider>
<Counter countAtom={count1Atom} name="count1" />
<Counter countAtom={count2Atom} name="count2" />
<Product />
</Provider>
)

await findByText('commits: 1, count1: 0')
await findByText('commits: 1, count2: 0')
await findByText('commits: 1, product: 0')

await waitFor(() => {
getByText('commits: 1, count1: 0')
getByText('commits: 1, count2: 0')
getByText('commits: 1, product: 0')
})
fireEvent.click(getByText('button-count1'))
await findByText('commits: 2, count1: 1')
await findByText('commits: 1, count2: 0')
await findByText('commits: 1, product: 0')

await waitFor(() => {
getByText('commits: 2, count1: 1')
getByText('commits: 1, count2: 0')
getByText('commits: 1, product: 0')
})
fireEvent.click(getByText('button-count2'))
await findByText('commits: 2, count1: 1')
await findByText('commits: 2, count2: 1')
await findByText('commits: 2, product: 1')
await waitFor(() => {
getByText('commits: 2, count1: 1')
getByText('commits: 2, count2: 1')
getByText('commits: 2, product: 1')
})
})

it('works with async get', async () => {
Expand Down Expand Up @@ -726,14 +736,16 @@ it('updates two atoms in child useEffect', async () => {
)
}

const { findByText } = render(
const { getByText } = render(
<Provider>
<Counter />
</Provider>
)

await findByText('countA: 1')
await findByText('countB: 2')
await waitFor(() => {
getByText('countA: 1')
getByText('countB: 2')
})
})

it('set atom right after useEffect (#208)', async () => {
Expand Down Expand Up @@ -816,16 +828,22 @@ it('works with Brige', async () => {
</Provider>
)

await findByText('count: 0')
await findByText('child: 0')
await waitFor(() => {
getByText('count: 0')
getByText('child: 0')
})

fireEvent.click(getByText('button'))
await findByText('count: 1')
await findByText('child: 1')
await waitFor(() => {
getByText('count: 1')
getByText('child: 1')
})

fireEvent.click(getByText('child'))
await findByText('count: 2')
await findByText('child: 2')
await waitFor(() => {
getByText('count: 2')
getByText('child: 2')
})
})

it('only relevant render function called (#156)', async () => {
Expand Down

0 comments on commit 3503fda

Please sign in to comment.