react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ui / dom / components / __tests__ / ReactDOMButton-test.js
81171 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @emails react-core9*/1011"use strict";1213/*jshint evil:true */1415var mocks = require('mocks');1617describe('ReactDOMButton', function() {18var React;19var ReactTestUtils;2021var onClick = mocks.getMockFunction();2223function expectClickThru(button) {24onClick.mockClear();25ReactTestUtils.Simulate.click(button.getDOMNode());26expect(onClick.mock.calls.length).toBe(1);27}2829function expectNoClickThru(button) {30onClick.mockClear();31ReactTestUtils.Simulate.click(button.getDOMNode());32expect(onClick.mock.calls.length).toBe(0);33}3435function mounted(button) {36button = ReactTestUtils.renderIntoDocument(button);37return button;38}3940beforeEach(function() {41React = require('React');42ReactTestUtils = require('ReactTestUtils');43});4445it('should forward clicks when it starts out not disabled', function() {46expectClickThru(mounted(<button onClick={onClick} />));47});4849it('should not forward clicks when it starts out disabled', function() {50expectNoClickThru(51mounted(<button disabled={true} onClick={onClick} />)52);53});5455it('should forward clicks when it becomes not disabled', function() {56var btn = mounted(<button disabled={true} onClick={onClick} />);57btn.setProps({disabled: false});58expectClickThru(btn);59});6061it('should not forward clicks when it becomes disabled', function() {62var btn = mounted(<button onClick={onClick} />);63btn.setProps({disabled: true});64expectNoClickThru(btn);65});6667it('should work correctly if the listener is changed', function() {68var btn = mounted(69<button disabled={true} onClick={function() {}} />70);7172btn.setProps({73disabled: false,74onClick: onClick75});7677expectClickThru(btn);78});79});808182