Skip to content

Commit 3c5d204

Browse files
committed
Fix up tests; can't rely on order of attributes anymore
1 parent c3bdd62 commit 3c5d204

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

specs/draggable.spec.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('react-draggable', function () {
1818

1919
afterEach(function() {
2020
try {
21-
React.unmountComponentAtNode(React.findDOMNode(drag).parentNode);
22-
// TestUtils.Simulate.mouseUp(ReactDOM.findDOMNode(drag));
21+
TestUtils.Simulate.mouseUp(ReactDOM.findDOMNode(drag)); // reset user-select
22+
React.unmountComponentAtNode(ReactDOM.findDOMNode(drag).parentNode);
2323
} catch(e) { return; }
2424
});
2525

@@ -40,9 +40,13 @@ describe('react-draggable', function () {
4040
it('should pass style and className properly from child', function () {
4141
drag = (<Draggable><div className="foo" style={{color: 'black'}}/></Draggable>);
4242

43-
expect(renderToHTML(drag)).toEqual('<div class="foo react-draggable" ' +
44-
'style="touch-action:none;color:black;transform:translate(0px,0px);' + dashedBrowserPrefix +
45-
'transform:translate(0px,0px);" data-reactid=".1"></div>');
43+
var node = renderToNode(drag);
44+
if ('touchAction' in document.body.style) {
45+
expect(node.getAttribute('style')).toMatch('touch-action: none');
46+
}
47+
expect(node.getAttribute('style')).toMatch('color: black');
48+
expect(node.getAttribute('style')).toMatch(dashedBrowserPrefix + 'transform: translate\\\(0px, 0px\\\)');
49+
expect(node.getAttribute('class')).toEqual('foo react-draggable');
4650
});
4751

4852
// NOTE: this runs a shallow renderer, which DOES NOT actually render <DraggableCore>
@@ -57,14 +61,14 @@ describe('react-draggable', function () {
5761
<div
5862
className="react-draggable"
5963
style={{
60-
'transform': 'translate(0px,0px)',
61-
[browserPrefix + 'Transform']: 'translate(0px,0px)'
64+
[browserPrefix + 'Transform']: 'translate(0px, 0px)'
6265
}}
6366
transform={null} />
6467
</DraggableCore>
6568
);
69+
6670
// Not easy to actually test equality here. The functions are bound as static props so we can't test those easily.
67-
var toOmit = ['onStart', 'onStop', 'onDrag'];
71+
var toOmit = ['onStart', 'onStop', 'onDrag', 'onMouseDown', 'children'];
6872
expect(_.isEqual(
6973
_.omit(output.props, toOmit),
7074
_.omit(expected.props, toOmit))
@@ -225,8 +229,7 @@ describe('react-draggable', function () {
225229

226230
var style = node.getAttribute('style');
227231
expect(dragged).toEqual(true);
228-
// No idea why the spacing is different here
229-
expect(style.indexOf('transform:translate(0px,0px);')).not.toEqual(-1);
232+
expect(style.indexOf('transform: translate(0px, 0px);')).not.toEqual(-1);
230233
});
231234

232235
it('should detect if an element is instanceof SVGElement and set state.isElementSVG to true', function() {
@@ -261,12 +264,11 @@ describe('react-draggable', function () {
261264

262265
var transform = node.getAttribute('transform');
263266
expect(transform.indexOf('translate(100,100)')).not.toEqual(-1);
264-
265267
});
266268

267269
it('should add and remove user-select styles', function () {
268270
// Karma runs in firefox in our tests
269-
var userSelectStyle = ';user-select: none;' + dashedBrowserPrefix + 'user-select: none;';
271+
var userSelectStyle = ';' + dashedBrowserPrefix + 'user-select: none;';
270272

271273
drag = TestUtils.renderIntoDocument(
272274
<Draggable>
@@ -285,7 +287,7 @@ describe('react-draggable', function () {
285287

286288
it('should not add and remove user-select styles when disabled', function () {
287289
// Karma runs in firefox in our tests
288-
var userSelectStyle = ';user-select: none;' + dashedBrowserPrefix + 'user-select: none;';
290+
var userSelectStyle = ';' + dashedBrowserPrefix + 'user-select: none;';
289291

290292
drag = TestUtils.renderIntoDocument(
291293
<Draggable enableUserSelectHack={false}>
@@ -447,7 +449,11 @@ describe('react-draggable', function () {
447449
});
448450

449451
function renderToHTML(component) {
450-
return ReactDOM.findDOMNode(TestUtils.renderIntoDocument(component)).outerHTML;
452+
return renderToNode(component).outerHTML;
453+
}
454+
455+
function renderToNode(component) {
456+
return ReactDOM.findDOMNode(TestUtils.renderIntoDocument(component));
451457
}
452458

453459
// Simulate a movement; can't use TestUtils here because it uses react's event system only,

0 commit comments

Comments
 (0)