question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad typing for `toHaveBeenCalledOnceWith` causing problems

See original GitHub issue

Bug

  • package version: 3.1.0
  • node version: 18.10.0
  • npm (or yarn) version: 8.19.2

What happened:

A test with the following line passes, but TypeScript complains with Expected 0 arguments, but got 1. ts(2554):

expect(revealSpy).toHaveBeenCalledOnceWith({ nodes: [node], index, parent });

reveal and revealSpy are defined as follows:

const revealSpy = jest.spyOn(mdastUtilHidden, 'reveal').mockImplementation(() => undefined);

// Exported as part of mdastUtilHidden
function reveal<Nodes extends Hidden[]>({
  nodes,
  index,
  parent
}: {
  nodes: Nodes;
  index: number;
  parent: Parent<Node<Data>>;
}) {
  parent.children.splice(
    index,
    1,
    ...nodes.flatMap((n) => n.hiddenChildren.map((n) => removePosition(n)))
  );
}

I saw a recent commit described as “fixing toHaveBeenCalledOnceWith,” so this may be a regression. Potentially related to #517. I’ve used @ts-expect-error to ignore the TS error for now. EDIT: expect(...).toHaveBeenNthCalledWith(1, ...) also works. Thanks for your work on this package!

Reproduction repository: https://github.com/Xunnamius/unified-utils/blob/b84a05ab0a10dd38b2c46062452f6c3e6cec194a/packages/mdast-util-hidden/test/unit-index.test.ts#L215

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

2reactions
keeganwittcommented, Nov 23, 2022

Simen just did a 3.2.0 release that contains this fix.

1reaction
keeganwittcommented, Oct 25, 2022

Yea, this was a simple goof in the type file. We currently lack test coverage of our types, but this is something we plan on adding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'toHaveBeenCalledOnceWith' does not exist on type ...
After migrating my Jasmine-Karma code to Jest, I am facing this issue : Property 'toHaveBeenCalledOnceWith' does not exist on type 'JestMatchers ...
Read more >
@types/jasmine toHaveBeenCalledWith infers parameters for ...
I go as far as to say, this is a bug in the typings if it means users are getting type errors when...
Read more >
Expect - Jest
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" ......
Read more >
What is Good Accuracy When it Comes to Typing?
In typing, though, settling for 90% accuracy is a huge mistake. If 10% of the words you type contain errors, you can hardly...
Read more >
Everything you need to know to pass a typing test
A typing test is a practical test that measures your typing speed and ... Poor habits can cause hand pain, which will reduce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found