Fix a few Transition-related tests

This commit is contained in:
Ryan Gossiaux
2021-12-30 17:52:03 -10:00
parent 839bb55e40
commit 00d92048dc
2 changed files with 33 additions and 5 deletions

View File

@@ -63,6 +63,16 @@ beforeAll(() => {
}) })
afterAll(() => jest.restoreAllMocks()) afterAll(() => jest.restoreAllMocks())
function nextFrame() {
return new Promise<void>((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
}
describe('safeguards', () => { describe('safeguards', () => {
it.each([ it.each([
['ListboxButton', ListboxButton], ['ListboxButton', ListboxButton],
@@ -610,8 +620,7 @@ describe('Rendering composition', () => {
describe('Composition', () => { describe('Composition', () => {
// TODO: fix this test it(
it.skip(
'should be possible to wrap the ListboxOptions with a Transition component', 'should be possible to wrap the ListboxOptions with a Transition component',
suppressConsoleLogs(async () => { suppressConsoleLogs(async () => {
let orderFn = jest.fn() let orderFn = jest.fn()
@@ -653,6 +662,9 @@ describe('Composition', () => {
await click(getListboxButton()) await click(getListboxButton())
// Wait for all transitions to finish
await nextFrame()
// Verify that we tracked the `mounts` and `unmounts` in the correct order // Verify that we tracked the `mounts` and `unmounts` in the correct order
expect(orderFn.mock.calls).toEqual([ expect(orderFn.mock.calls).toEqual([
['Mounting - Listbox'], ['Mounting - Listbox'],

View File

@@ -26,6 +26,16 @@ beforeAll(() => {
}) })
afterAll(() => jest.restoreAllMocks()) afterAll(() => jest.restoreAllMocks())
function nextFrame() {
return new Promise<void>((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
}
describe('Safe guards', () => { describe('Safe guards', () => {
it.each([ it.each([
['MenuButton', MenuButton], ['MenuButton', MenuButton],
@@ -464,7 +474,7 @@ describe('Rendering composition', () => {
}) })
describe('Composition', () => { describe('Composition', () => {
it.skip( it(
'should be possible to wrap the MenuItems with a Transition component', 'should be possible to wrap the MenuItems with a Transition component',
suppressConsoleLogs(async () => { suppressConsoleLogs(async () => {
let orderFn = jest.fn() let orderFn = jest.fn()
@@ -506,6 +516,9 @@ describe('Composition', () => {
await click(getMenuButton()) await click(getMenuButton())
// Wait for all transitions to finish
await nextFrame()
// Verify that we tracked the `mounts` and `unmounts` in the correct order // Verify that we tracked the `mounts` and `unmounts` in the correct order
expect(orderFn.mock.calls).toEqual([ expect(orderFn.mock.calls).toEqual([
['Mounting - Menu'], ['Mounting - Menu'],
@@ -517,8 +530,8 @@ describe('Composition', () => {
}) })
) )
it.skip( it(
'should be possible to wrap the MenuItems with a Transition.Child component', 'should be possible to wrap the MenuItems with a TransitionChild component',
suppressConsoleLogs(async () => { suppressConsoleLogs(async () => {
let orderFn = jest.fn() let orderFn = jest.fn()
render( render(
@@ -559,6 +572,9 @@ describe('Composition', () => {
await click(getMenuButton()) await click(getMenuButton())
// Wait for all transitions to finish
await nextFrame()
// Verify that we tracked the `mounts` and `unmounts` in the correct order // Verify that we tracked the `mounts` and `unmounts` in the correct order
expect(orderFn.mock.calls).toEqual([ expect(orderFn.mock.calls).toEqual([
['Mounting - Menu'], ['Mounting - Menu'],