Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to trigger decrement callback for Spinbutton in tests?#17195

Unanswered
mccuna asked this question inQ&A
Discussion options

Hey,

I'm trying to test the decrement callback of aSpinButton, but it seems it's not called when I fire the click event on the decrement button. Am I missing something?

test(`SpinButton decrement callback should be called when clicking the decrement button`,()=>{consthandleDecrement=jest.fn();consthandleIncrement=jest.fn();consthandleChange=jest.fn();render(<SpinButtononChange={handleChange}value="20"onIncrement={handleIncrement}onDecrement={handleDecrement}incrementButtonAriaLabel="Increase value by 1"decrementButtonAriaLabel="Decrease value by 1"/>);constdecrementButton=screen.getByRole("button",{name:/decreasevalueby1/i});fireEvent.click(decrementButton);expect(handleDecrement).toBeCalled();});

I've also put together a codesandbox if it proves useful:https://codesandbox.io/s/trigger-splinbutton-decrement-g918h?file=/src/Sample.test.tsx.

Versions used:

"dependencies": {"@fluentui/react":"7.128.1","@testing-library/react":"11.2.5","react":"16.13.0","react-dom":"16.13.0","react-scripts":"3.4.1"  },"devDependencies": {"@types/react":"16.13.0","@types/react-dom":"16.13.0","typescript":"4.1.3"  },
You must be logged in to vote

Replies: 1 comment

Comment options

Hey@mccuna, have you checked test files of SpinButton, they should have increment/decrement:https://github.com/microsoft/fluentui/blob/master/packages/react-components/react-spinbutton/library/src/components/SpinButton/SpinButton.test.tsx

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@mccuna@ValentinaKozlova

[8]ページ先頭

©2009-2025 Movatter.jp