-
Notifications
You must be signed in to change notification settings - Fork 0
/
matcher-nots.js
1 lines (1 loc) · 1.62 KB
/
matcher-nots.js
1
[{"content":"# Matchers\n\nMatchers help make sure that a value is what we expect it to be. \n\nA project generated by Create React App has access to all the matchers included in Jest, as well as matchers defined in the @testing-library/jest-dom package.\n\n| Name | Link |\n|---------------------------|--------------------------------------------------------------------------------------------|\n| Jest | https://jestjs.io/docs/mock-function-api\n| @testing-library/jest-dom | https://github.com/testing-library/jest-dom |\n\n\n","type":"text","id":"x1gjv"},{"content":"import { screen, render, within } from '@testing-library/react';\n\nfunction FormData() {\n return (\n <div>\n <button>Go Back</button>\n <form aria-label=\"form\">\n <button>Save</button>\n <button>Cancel</button>\n </form>\n </div>\n )\n}\nrender(<FormData />);","type":"code","id":"0j6z9"},{"content":"function toContainRole(container, role, quantity = 1) {\n const elements = within(container).queryAllByRole(role);\n\n if (elements.length === quantity) {\n return {\n pass: true\n };\n }\n\n return {\n pass: false,\n message: () => `Expected to find ${quantity} ${role} elements. Found ${elements.length} instead.`\n }\n}\n\nexpect.extend({ toContainRole });","type":"code","id":"1s8ut"},{"content":"test('the form displays two buttons', () => {\n render(<FormData />);\n\n const form = screen.getByRole('form');\n\n expect(form).toContainRole('link', 10);\n});","type":"code","id":"gfgqo"}]