Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81171 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
"use strict";
13
14
/*jshint evil:true */
15
16
var mocks = require('mocks');
17
18
describe('ReactDOMButton', function() {
19
var React;
20
var ReactTestUtils;
21
22
var onClick = mocks.getMockFunction();
23
24
function expectClickThru(button) {
25
onClick.mockClear();
26
ReactTestUtils.Simulate.click(button.getDOMNode());
27
expect(onClick.mock.calls.length).toBe(1);
28
}
29
30
function expectNoClickThru(button) {
31
onClick.mockClear();
32
ReactTestUtils.Simulate.click(button.getDOMNode());
33
expect(onClick.mock.calls.length).toBe(0);
34
}
35
36
function mounted(button) {
37
button = ReactTestUtils.renderIntoDocument(button);
38
return button;
39
}
40
41
beforeEach(function() {
42
React = require('React');
43
ReactTestUtils = require('ReactTestUtils');
44
});
45
46
it('should forward clicks when it starts out not disabled', function() {
47
expectClickThru(mounted(<button onClick={onClick} />));
48
});
49
50
it('should not forward clicks when it starts out disabled', function() {
51
expectNoClickThru(
52
mounted(<button disabled={true} onClick={onClick} />)
53
);
54
});
55
56
it('should forward clicks when it becomes not disabled', function() {
57
var btn = mounted(<button disabled={true} onClick={onClick} />);
58
btn.setProps({disabled: false});
59
expectClickThru(btn);
60
});
61
62
it('should not forward clicks when it becomes disabled', function() {
63
var btn = mounted(<button onClick={onClick} />);
64
btn.setProps({disabled: true});
65
expectNoClickThru(btn);
66
});
67
68
it('should work correctly if the listener is changed', function() {
69
var btn = mounted(
70
<button disabled={true} onClick={function() {}} />
71
);
72
73
btn.setProps({
74
disabled: false,
75
onClick: onClick
76
});
77
78
expectClickThru(btn);
79
});
80
});
81
82