@@ -5,6 +5,7 @@ import Uploader from '../index';
5
5
import React from 'react' ;
6
6
import ReactDOM from 'react-dom' ;
7
7
import TestUtils from 'react-dom/test-utils' ;
8
+ import { format } from 'util' ;
8
9
const { Simulate } = TestUtils ;
9
10
import sinon from 'sinon' ;
10
11
@@ -47,15 +48,24 @@ const makeDataTransferItem = item => {
47
48
describe ( 'uploader' , ( ) => {
48
49
let requests ;
49
50
let xhr ;
51
+ let errorMock ;
50
52
51
53
beforeEach ( ( ) => {
52
54
xhr = sinon . useFakeXMLHttpRequest ( ) ;
53
55
requests = [ ] ;
54
56
xhr . onCreate = req => requests . push ( req ) ;
57
+
58
+ const originalConsoleError = global . console . error ;
59
+ errorMock = jest . spyOn ( global . console , 'error' ) ;
60
+ errorMock . mockImplementation ( ( message , ...otherParams ) => {
61
+ originalConsoleError ( message , ...otherParams ) ;
62
+ throw new Error ( format ( message , ...otherParams ) ) ;
63
+ } ) ;
55
64
} ) ;
56
65
57
66
afterEach ( ( ) => {
58
67
xhr . restore ( ) ;
68
+ errorMock . mockRestore ( ) ;
59
69
} ) ;
60
70
61
71
describe ( 'ajax uploader' , ( ) => {
@@ -116,6 +126,55 @@ describe('uploader', () => {
116
126
} ) ;
117
127
} ) ;
118
128
129
+ it ( 'should pass through data attributes' , done => {
130
+ ReactDOM . render (
131
+ (
132
+ < Uploader
133
+ data-testid = "data-testid"
134
+ data-my-custom-attr = "custom data attribute"
135
+ />
136
+ ) ,
137
+ node ,
138
+ function init ( ) {
139
+ expect ( TestUtils . findRenderedDOMComponentWithTag ( this , 'input' )
140
+ . getAttribute ( 'data-testid' ) )
141
+ . to . be ( 'data-testid' ) ;
142
+ expect ( TestUtils . findRenderedDOMComponentWithTag ( this , 'input' )
143
+ . getAttribute ( 'data-my-custom-attr' ) )
144
+ . to . be ( 'custom data attribute' ) ;
145
+ done ( ) ;
146
+ }
147
+ ) ;
148
+ } ) ;
149
+
150
+ it ( 'should pass through aria attributes' , done => {
151
+ ReactDOM . render ( < Uploader aria-label = "Upload a file" /> , node , function init ( ) {
152
+ expect ( TestUtils . findRenderedDOMComponentWithTag ( this , 'input' )
153
+ . getAttribute ( 'aria-label' ) )
154
+ . to . be ( 'Upload a file' ) ;
155
+ done ( ) ;
156
+ } ) ;
157
+ } ) ;
158
+
159
+ it ( 'should pass through role attributes' , done => {
160
+ ReactDOM . render ( < Uploader role = "button" /> , node , function init ( ) {
161
+ expect ( TestUtils . findRenderedDOMComponentWithTag ( this , 'input' )
162
+ . getAttribute ( 'role' ) )
163
+ . to . be ( 'button' ) ;
164
+ done ( ) ;
165
+ } ) ;
166
+ } ) ;
167
+
168
+ it ( 'should not pass through unknown props' , done => {
169
+ ReactDOM . render ( < Uploader customProp = "This shouldn't be rendered to DOM" /> ,
170
+ node ,
171
+ ( ) => {
172
+ // Fails when React reports unrecognized prop is added to DOM in console.error
173
+ done ( ) ;
174
+ }
175
+ ) ;
176
+ } ) ;
177
+
119
178
it ( 'create works' , ( ) => {
120
179
expect ( TestUtils . scryRenderedDOMComponentsWithTag ( uploader , 'span' ) . length ) . to . be ( 1 ) ;
121
180
} ) ;
0 commit comments