From ba519c0033b495dedef6b9aef0f9fb7fcbbdd511 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Mon, 17 Oct 2011 21:52:24 +1000 Subject: [PATCH] Updated string test to catch both types of strings... --- classtweak.js | 2 +- test/specs/queryselector.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/classtweak.js b/classtweak.js index eb9660b..dbb1fa9 100644 --- a/classtweak.js +++ b/classtweak.js @@ -66,7 +66,7 @@ function classtweak(elements, initAction) { } // tweak // check the elements - if (typeof elements == 'string') { + if (typeof elements == 'string' || elements instanceof String) { elements = document.querySelectorAll(elements); } else if (! Array.isArray(elements)) { diff --git a/test/specs/queryselector.js b/test/specs/queryselector.js index 5e38ce4..f1b3166 100644 --- a/test/specs/queryselector.js +++ b/test/specs/queryselector.js @@ -42,4 +42,12 @@ describe('query selector tweaks', function() { expect(elements[1].className).toEqual(''); expect(elements[2].className).toEqual(''); }); + + it('can handle string objects', function() { + classtweak('section[data-route]', '+bounce'); + classtweak(new String('section'), '!bounce'); + expect(elements[0].className).toEqual('bounce'); + expect(elements[1].className).toEqual(''); + expect(elements[2].className).toEqual(''); + }); }); \ No newline at end of file