Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest: Can not test onTruncate method #142

Open
Kazimirkas opened this issue Feb 4, 2021 · 3 comments
Open

Jest: Can not test onTruncate method #142

Kazimirkas opened this issue Feb 4, 2021 · 3 comments

Comments

@Kazimirkas
Copy link

Kazimirkas commented Feb 4, 2021

The following test fails with 0 value. Can you please help and mention, what am I doing wrong?

import React from "react";
import { mount } from "enzyme";
import Truncate from "react-truncate";

it("on Truncate", () => {
  const onTr = jest.fn();
  const layout = mount(<Truncate onTruncate={onTr}>Hello world</Truncate>);
  expect(onTr).toBeCalledTimes(1);
});
@WORLDI
Copy link

WORLDI commented Aug 4, 2021

I have the same problem too.

@WORLDI
Copy link

WORLDI commented Aug 4, 2021

how to resolve the problem?

@WORLDI
Copy link

WORLDI commented Aug 6, 2021

I found the way to test onTruncate, just add
act(() => { jest.advanceTimersByTime(100); });
to your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants