Open efilion opened 2 years ago
This is incredible, I've only had a brief read through as I'm very busy lately but when I get time I will try to turn this into some documentation that everyone can reference if they need to test, and I'll try to have a think about how testing could be improved/made easier as you suggested
Thank you so much for documenting this
Had a hell of a time trying to figure this one out. Thought I would share the solution I found here to help anyone else trying to set up automated Jest tests with ReactChessboard.
Solution for writing automated tests with Jest
npx create-react-app react-chessboard-jest-testing
,cd react-chessboard-jest-testing
npm i react-chessboard
npm i --save-dev react-dnd-test-utils react-dnd-test-backend
Getting Jest to play nicely with ESM modules
/* act and await tick to ensure setup animation completes
afterEach(() => { cleanup() })
test('e2 to e4', async () => { let e2pawn = document.querySelector('[data-square=e2] [draggable]'); let e4square = document.querySelector('[data-square=e4]')
expect(e2pawn).toBeInTheDocument(); expect(e4square.querySelector('[draggable]')).not.toBeInTheDocument(); await fireDragDrop(e2pawn, e4square); expect(e2pawn).not.toBeInTheDocument(); expect(e4square.querySelector('[draggable]')).toBeInTheDocument(); })
test('can find white pawn', () => { render( <>
)
let e2pawn = screen.getByRole('widget', { name: /white e2 pawn/i }); expect(e2pawn).toBeInTheDocument(); })