-
-
Save dineshigdd/ae2ec084d8c3ad23bd3cd7decece8edf to your computer and use it in GitHub Desktop.
You can add this code in the App.test.js. It is not necessary to create another test file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('performs division', () => { | |
render(<App />); | |
const inputElement = screen.getByRole('textbox'); | |
// Check the value of the textbox (initially it should be an empty string) | |
expect(inputElement.value).toBe(''); | |
// Simulate clicking the buttons to enter the expression "2+3" into the calculator | |
fireEvent.click(screen.getByText('1')); | |
expect( inputElement.value ).toBe("1") | |
fireEvent.click(screen.getByText('0')); | |
expect( inputElement.value ).toBe("10") | |
// expect(inputElement.textContent).toBe(' 2'); | |
fireEvent.click(screen.getByText('/')); | |
expect(inputElement.value).toBe('10/'); | |
fireEvent.click(screen.getByText('2')); | |
expect(inputElement.value).toBe('10/2'); | |
// Simulate clicking the "=" button | |
fireEvent.click(screen.getByText('=')); | |
//select the 'result' div and check if it's value is 5 | |
const resultElement = screen.getByTestId('result'); | |
expect(resultElement.textContent).toBe('5');//or expect(resultElement).toHaveTextContent('5') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment