Bad typing for `toHaveBeenCalledOnceWith` causing problems
See original GitHub issueBug
package
version: 3.1.0node
version: 18.10.0npm
(oryarn
) 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:
- Created a year ago
- Reactions:1
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Simen just did a 3.2.0 release that contains this fix.
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.