cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-plugin-device-orientation git commit: CB-8458 Fixes false failure of test, when compass hardware is not available
Date Wed, 11 Feb 2015 14:49:59 GMT
Repository: cordova-plugin-device-orientation
Updated Branches:
  refs/heads/master 4d36668cb -> 7f813a89a


CB-8458 Fixes false failure of test, when compass hardware is not available

* Factor out compass detection to beforeEach
* Remove false-failure spec


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/commit/7f813a89
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/tree/7f813a89
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/diff/7f813a89

Branch: refs/heads/master
Commit: 7f813a89a1438bbdc35d5df63fbbd380a7bc1ee5
Parents: 4d36668
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Wed Feb 11 17:48:46 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Wed Feb 11 17:48:46 2015 +0300

----------------------------------------------------------------------
 tests/tests.js | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/blob/7f813a89/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index c5ddc59..2812453 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -29,7 +29,6 @@ exports.defineAutoTests = function () {
         unexpectedFailure = "Forced failure: error callback should not have been called";
 
     describe('Compass (navigator.compass)', function () {
-        var hardwarefailure = false;
         beforeEach(function () {
             jasmine.Expectation.addMatchers({
                 toFailWithMessage: function () {
@@ -49,15 +48,22 @@ exports.defineAutoTests = function () {
             });
         });
 
-        it("compass.hardwarecheck is compass supported", function (done) {
-            navigator.compass.getCurrentHeading(function onSuccess() { done(); },
-                function onError(error) {
-                    if (error.code == CompassError.COMPASS_NOT_SUPPORTED) {
-                        hardwarefailure = true;
-                        expect(this).toFailWithMessage("The device does not have compass
support. Any tests relying on support will be marked pending.");
-                    }
-                    done();
-                });
+        var isCompassAvailable = true;
+
+        beforeEach(function (done) {
+            if (!isCompassAvailable) {
+                // if we're already ensured that compass is not available, no need to check
it again
+                done();
+                return;
+            }
+            // Try to access compass device, and if it is not available
+            // set hardwarefailure flag to mark some tests pending
+            navigator.compass.getCurrentHeading(done, function (error) {
+                if (error.code == CompassError.COMPASS_NOT_SUPPORTED) {
+                    isCompassAvailable = false;
+                }
+                done();
+            });
         });
 
         it("compass.spec.1 should exist", function () {
@@ -71,7 +77,7 @@ exports.defineAutoTests = function () {
         });
 
         it("compass.spec.3 getCurrentHeading success callback should be called with a Heading
object", function (done) {
-            if (hardwarefailure) {
+            if (!isCompassAvailable) {
                 pending();
             }
             navigator.compass.getCurrentHeading(function (a) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message