Exemplo n.º 1
0
        public void TypeTests()
        {
            ResetQunit();
            // Type
            var type = jQuery("#check2").Attr("type");
            var thrown = false;
            try
            {
                jQuery("#check2").Attr("type", "hidden");
            }
            catch
            {
                thrown = true;
            }
            Assert.IsTrue(thrown, "Exception thrown when trying to change type property");
            Assert.AreEqual(type, jQuery("#check2").Attr("type"), "Verify that you can't change the type of an input element");

            var check = document.CreateElement("input");
            thrown = true;
            try
            {
                jQuery(check).Attr("type", "checkbox");
            }
            catch
            {
                thrown = false;
            }
            Assert.IsTrue(thrown, "Exception thrown when trying to change type property");
            Assert.AreEqual("checkbox", jQuery(check).Attr("type"), "Verify that you can change the type of an input element that isn't in the DOM");


            ResetQunit();


            var jcheck = jQuery("<input />");
            thrown = false;
            try
            {
                jcheck.Attr("type", "checkbox");
            }
            catch
            {
                thrown = true;
            }
            Assert.IsFalse(thrown, "No exception thrown when trying to change type property");
            Assert.AreEqual("checkbox", jcheck.Attr("type"), "Verify that you can change the type of an input element that isn't in the DOM");

            var button = jQuery("#button");
            thrown = false;
            try
            {
                button.Attr("type", "submit");
            }
            catch
            {
                thrown = true;
            }
            Assert.IsTrue(thrown, "Exception thrown when trying to change type property");
            Assert.AreEqual("button", button.Attr("type"), "Verify that you can't change the type of a button element");

            var jradio = new CQ("<input>", "{ 'value': 'sup', 'type': 'radio' }", Dom);
            jradio = jradio.AppendTo("#testForm");
            Assert.AreEqual(jradio.Val(), "sup", "Value is not reset when type is set after value on a radio");

            // Setting attributes on svg elements (bug #3116)
            var jsvg = jQuery("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>"
                + "<circle cx='200' cy='200' r='150' />"
            + "</svg>").AppendTo("body");
            Assert.AreEqual(jsvg.Attr("cx", 100).Attr("cx"), "100", "Set attribute on svg element");
            jsvg.Remove();

        }