|
| 1 | +const React = require('react'); |
1 | 2 | const assert = require('assert'); |
2 | | -const { camelCase, invertObject } = require('../lib/utilities'); |
| 3 | +const { |
| 4 | + camelCase, |
| 5 | + invertObject, |
| 6 | + isCustomComponent, |
| 7 | + reactSupportsUnknownAttributes |
| 8 | +} = require('../lib/utilities'); |
3 | 9 |
|
4 | 10 | describe('utilties.camelCase', () => { |
5 | 11 | [undefined, null, 1337, {}, []].forEach(value => { |
@@ -80,4 +86,44 @@ describe('utilities.invertObject', () => { |
80 | 86 | ); |
81 | 87 | }); |
82 | 88 | }); |
| 89 | + |
| 90 | + describe('utilities.isCustomComponent', () => { |
| 91 | + it('returns true if the tag contains a hyphen and is not in the whitelist', () => { |
| 92 | + assert.equal(isCustomComponent('my-custom-element'), true); |
| 93 | + }); |
| 94 | + |
| 95 | + it('returns false if the tag is in the whitelist', () => { |
| 96 | + assert.equal(isCustomComponent('annotation-xml'), false); |
| 97 | + assert.equal(isCustomComponent('color-profile'), false); |
| 98 | + assert.equal(isCustomComponent('font-face'), false); |
| 99 | + }); |
| 100 | + |
| 101 | + it('returns true if the props contains an `is` key', () => { |
| 102 | + assert.equal(isCustomComponent('button', { is: 'custom-button' }), true); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + describe('utilities.reactSupportsUnknownAttributes', () => { |
| 107 | + let actualVersion; |
| 108 | + beforeEach(() => { |
| 109 | + actualVersion = React.version; |
| 110 | + }); |
| 111 | + |
| 112 | + afterEach(() => { |
| 113 | + React.version = actualVersion; |
| 114 | + }); |
| 115 | + |
| 116 | + it('should return true for React 16 and above', () => { |
| 117 | + React.version = '16.6.0'; |
| 118 | + assert.equal(reactSupportsUnknownAttributes(), true); |
| 119 | + }); |
| 120 | + |
| 121 | + it('should return false for React < 16', () => { |
| 122 | + React.version = '15.1.2'; |
| 123 | + assert.equal(reactSupportsUnknownAttributes(), false); |
| 124 | + |
| 125 | + React.version = '0.14'; |
| 126 | + assert.equal(reactSupportsUnknownAttributes(), false); |
| 127 | + }); |
| 128 | + }); |
83 | 129 | }); |
0 commit comments