|
1 | 1 | const {getRole} = require('../../lib/utils/get-role')
|
2 |
| -const {mockJSXAttribute, mockJSXOpeningElement} = require('./mocks') |
| 2 | +const {mockJSXAttribute, mockJSXConditionalAttribute, mockJSXOpeningElement} = require('./mocks') |
3 | 3 | const mocha = require('mocha')
|
4 | 4 | const describe = mocha.describe
|
5 | 5 | const it = mocha.it
|
6 | 6 | const expect = require('chai').expect
|
7 | 7 |
|
8 | 8 | describe('getRole', function () {
|
| 9 | + it('returns undefined when polymorphic prop is set with a non-literal expression', function () { |
| 10 | + // <Box as={isNavigationOpen ? 'div' : 'nav'} /> |
| 11 | + const node = mockJSXOpeningElement('Box', [mockJSXConditionalAttribute('as', 'isNavigationOpen', 'div', 'nav')]) |
| 12 | + expect(getRole({}, node)).to.equal(undefined) |
| 13 | + }) |
| 14 | + |
| 15 | + it('returns undefined when role is set to non-literal expression', function () { |
| 16 | + // <Box role={isNavigationOpen ? 'generic' : 'navigation'} /> |
| 17 | + const node = mockJSXOpeningElement('Box', [ |
| 18 | + mockJSXConditionalAttribute('role', 'isNavigationOpen', 'generic', 'navigation'), |
| 19 | + ]) |
| 20 | + expect(getRole({}, node)).to.equal(undefined) |
| 21 | + }) |
| 22 | + |
| 23 | + it('returns `role` when set to a literal expression', function () { |
| 24 | + // <Box role="generic" /> |
| 25 | + const node = mockJSXOpeningElement('Box', [mockJSXAttribute('role', 'generic')]) |
| 26 | + expect(getRole({}, node)).to.equal('generic') |
| 27 | + }) |
| 28 | + |
9 | 29 | it('returns generic role for <span> regardless of attribute', function () {
|
10 | 30 | const node = mockJSXOpeningElement('span', [mockJSXAttribute('aria-label', 'something')])
|
11 | 31 | expect(getRole({}, node)).to.equal('generic')
|
|
0 commit comments