Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/mui-material/src/useLazyRipple/useLazyRipple.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { spy } from 'sinon';
import { act, createRenderer } from '@mui/internal-test-utils';
import useLazyRipple, { LazyRipple } from './useLazyRipple';
import { TouchRippleActions } from '../ButtonBase/TouchRipple';

describe('useLazyRipple', () => {
const { render } = createRenderer();

function Fixture({ onRipple }: { onRipple: (ripple: LazyRipple) => void }) {
const ripple = useLazyRipple();
onRipple(ripple);
return null;
}

it('resolves mount() even when no ripple is rendered', async () => {
let ripple!: LazyRipple;
render(
<Fixture
onRipple={(instance) => {
ripple = instance;
}}
/>,
);

await act(async () => {
ripple.start({} as React.SyntheticEvent);
});

await ripple.mount();

expect(ripple.shouldMount).to.equal(true);
expect(ripple.ref.current).to.equal(null);
});

it('forwards queued actions to the ripple when one is mounted', async () => {
let ripple!: LazyRipple;
render(
<Fixture
onRipple={(instance) => {
ripple = instance;
}}
/>,
);

const actions = { start: spy(), stop: spy(), pulsate: spy() };
ripple.ref.current = actions as unknown as TouchRippleActions;

const event = {} as React.SyntheticEvent;
await act(async () => {
ripple.start(event);
});
await ripple.mount();

expect(actions.start.callCount).to.equal(1);
expect(actions.start.firstCall.args[0]).to.equal(event);
});
});
2 changes: 1 addition & 1 deletion packages/mui-material/src/useLazyRipple/useLazyRipple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class LazyRipple {
if (this.shouldMount && !this.didMount) {
if (this.ref.current !== null) {
this.didMount = true;
this.mounted!.resolve();
}
this.mounted!.resolve();
}
};

Expand Down
Loading