Permalink
Browse files

default internal `query()` to qSA

  • Loading branch information...
1 parent d757fe6 commit 91914785865ac46e7e0daf3f24e75c547735c5b3 @rvagg rvagg committed Nov 28, 2012
Showing with 67 additions and 35 deletions.
  1. +1 −1 src/bonzo.js
  2. +32 −11 tests/selectorengine-test.js
  3. +34 −23 tests/tests.html
View
@@ -7,7 +7,6 @@
, doc = win.document
, html = doc.documentElement
, parentNode = 'parentNode'
- , query = null // used for setting a selector engine host
, specialAttributes = /^(checked|value|selected|disabled)$/i
, specialTags = /^(select|fieldset|table|tbody|tfoot|td|tr|colgroup)$/i // tags that we have trouble inserting *into*
, table = ['<table>', '</table>', 1]
@@ -59,6 +58,7 @@
, whitespaceRegex = /\s+/
, toString = String.prototype.toString
, unitless = { lineHeight: 1, zoom: 1, zIndex: 1, opacity: 1, boxFlex: 1, WebkitBoxFlex: 1, MozBoxFlex: 1 }
+ , query = doc.querySelectorAll && function (selector) { return doc.querySelectorAll(selector) }
, trim = String.prototype.trim ?
function (s) {
return s.trim()
@@ -1,16 +1,37 @@
/*global sink:true start:true Q:true dom:true $:true bowser:true ender:true*/
sink('Selector engine', function (test, ok) {
- test('run insert with created nodes', 1, function () {
- var node = $.create('<p>world</p>')[0]
- , node2 = $.create('<p>hello</p>')[0]
- $([node, node2]).prependTo('.prepend-with-engine')
- ok($('.prepend-with-engine p').length == 4, 'prepends 4 elements total')
- })
+ if (!document.querySelectorAll) {
+ test('use default selector engine', 1, function () {
+ bonzo._setQueryEngine(Q)
+ ok(true)
+ })
+ }
- test('run insert with existing nodes', 2, function () {
- $('.prepend-with-engine p').prependTo('.prepend-with-engine-move')
- ok($('.prepend-with-engine p').length === 0, 'prepend now has no elements')
- ok($('.prepend-with-engine-move p').length == 4, 'elements were moved to target selector')
- })
+ function insertCreatedNodes () {
+ var node = bonzo.create('<p>world</p>')[0]
+ , node2 = bonzo.create('<p>hello</p>')[0]
+ bonzo([node, node2]).prependTo('.prepend-with-engine')
+ ok(Q('.prepend-with-engine p').length == 4, 'prepends 4 elements total')
+ }
+
+ function insertExistingNodes () {
+ bonzo(Q('.prepend-with-engine p')).prependTo('.prepend-with-engine-move')
+ ok(Q('.prepend-with-engine p').length === 0, 'prepend now has no elements')
+ ok(Q('.prepend-with-engine-move p').length == 4, 'elements were moved to target selector')
+ bonzo(Q('.prepend-with-engine-move')).empty() // reset
+ }
+
+ test('pre-setQueryEngine() run insert with created nodes', 1, insertCreatedNodes)
+ test('pre-setQueryEngine() run insert with existing nodes', 2, insertExistingNodes)
+
+ if (document.querySelectorAll) {
+ test('set selector engine', 1, function () {
+ bonzo._setQueryEngine(Q)
+ ok(true)
+ })
+
+ test('post-setQueryEngine() run insert with created nodes', 1, insertCreatedNodes)
+ test('post-setQueryEngine() run insert with existing nodes', 2, insertExistingNodes)
+ }
})
View
@@ -26,28 +26,6 @@
display: none;
}
</style>
- <script src="../node_modules/sink-test/src/sink.js"></script>
- <script src="../node_modules/qwery/qwery.js"></script>
- <script src="../node_modules/bowser/bowser.js"></script>
- <script src="../src/bonzo.js"></script>
- <script type="text/javascript">
- var dom = bonzo
- var Q = qwery
- dom.setQueryEngine(Q)
- function $(s) {
- return dom(Q(s))
- }
- dom.aug(dom, $)
- </script>
- <script src="ender-js.js"></script>
- <script type="text/javascript">
- var ender = $.noConflict()
- dom.setQueryEngine = function() {}
- provide('bonzo', dom)
- ender._select = Q
- </script>
- <script src="../src/ender.js"></script>
- <!-- we now have an 'ender' object to test on that has Bonzo integrated via the bridge -->
</head>
<body>
<div id="fixtures">
@@ -152,13 +130,46 @@
<h1>Bonzo Tests</h1>
<ol id="tests"></ol>
+ <script src="../node_modules/sink-test/src/sink.js"></script>
+ <script src="../node_modules/qwery/qwery.js"></script>
+ <script src="../node_modules/bowser/bowser.js"></script>
+ <script src="../src/bonzo.js"></script>
+ <script type="text/javascript">
+ bonzo._setQueryEngine = bonzo.setQueryEngine
+ bonzo.setQueryEngine = function() {}
+ </script>
+ <script src="ender-js.js"></script>
+ <script type="text/javascript">
+ window.ender = $.noConflict()
+ window.Q = qwery
+ </script>
+
+ <!-- NOTE: selector engine tests go before we mess with the default engine and the rest of the environment-->
+ <script src="selectorengine-test.js"></script>
+ <script type="text/javascript">
+ sink('Post-init', function (test, ok) {
+ test('set up test environment', 1, function () {
+ window.dom = bonzo
+ window.$ = function $(s) {
+ return dom(Q(s))
+ }
+ //dom.setQueryEngine(Q)
+ dom.aug(dom, $)
+ provide('bonzo', dom)
+ ender._select = Q
+ ok(true)
+ })
+ })
+ </script>
+ <script src="../src/ender.js"></script>
+ <!-- we now have an 'ender' object to test on that has Bonzo integrated via the bridge -->
+
<script src="misc-test.js"></script>
<script src="traversal-test.js"></script>
<script src="layout-test.js"></script>
<script src="dommanip-test.js"></script>
<script src="dommanip_insertions-test.js"></script>
<script src="attributes-test.js"></script>
- <script src="selectorengine-test.js"></script>
<script src="emptycollection-test.js"></script>
<script src="bridge-test.js"></script>
<script>

0 comments on commit 9191478

Please sign in to comment.