CB-8443 Geolocation tests fail on Windows due to done is called multiple times
diff --git a/tests/tests.js b/tests/tests.js
index 4a99991..89fc957 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -25,7 +25,10 @@
},
succeed = function (done) {
expect(true).toBe(true);
- done();
+ // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach
+ setTimeout(function () {
+ done();
+ });
};
var isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone);
@@ -135,11 +138,20 @@
if (isWindowsStore) {
pending();
}
+ var self = this;
successWatch = navigator.geolocation.watchPosition(
function (p) {
+ // prevents done() to be called several times
+ if (self.done) return;
+ self.done = true;
+
expect(p.coords).toBeDefined();
expect(p.timestamp).toBeDefined();
- done();
+ // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach
+ setTimeout(function () {
+ done();
+ })
+
},
fail.bind(null, done),
{