Skip to content

Commit

Permalink
Lets debounce take more time in some tests (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Sep 6, 2024
1 parent b2bcab1 commit af87a8b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/react-codemirror/src/CypherEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const onChange = vi.fn((v: string) => {
});

global.IS_REACT_ACT_ENVIRONMENT = true;
const DEBOUNCE_TIME_WITH_MARGIN = DEBOUNCE_TIME + 100;

/** Avoids crash in test environment */
function mockEditorView(editorView: EditorView) {
Expand All @@ -31,7 +32,9 @@ function mockEditorView(editorView: EditorView) {
}

async function debounce() {
await new Promise((resolve) => setTimeout(resolve, DEBOUNCE_TIME));
await new Promise((resolve) =>
setTimeout(resolve, DEBOUNCE_TIME_WITH_MARGIN),
);
}

function getEditorValue() {
Expand Down Expand Up @@ -144,7 +147,7 @@ test.fails(
);

test('rerender should not cancel onChange', async () => {
// 1. value is updated ínternally
// 1. value is updated internally
ref.current.setValueAndFocus('changed');

// 2. editor is rerendered while a value update is still pending
Expand All @@ -158,11 +161,11 @@ test('rerender should not cancel onChange', async () => {
});

test('rerender with a previous update should not cancel onChange', async () => {
// 1. value is updated ínternally
// 1. value is updated internally
ref.current.setValueAndFocus('changed');
await debounce();

// 2. value is updated ínternally again
// 2. value is updated internally again
ref.current.setValueAndFocus('new change');

// 3. editor is rerendered while a value update is still pending
Expand Down

0 comments on commit af87a8b

Please sign in to comment.