Account for cases where the Pebble global is undefined

This commit is contained in:
Keegan
2016-02-27 08:51:54 +11:00
parent 1cd4590691
commit aa30ef7d7a
3 changed files with 26 additions and 8 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
+6 -2
View File
@@ -29,7 +29,11 @@ function Clay(config, customFn, options) {
self.config = config;
self.customFn = customFn || function() {};
self.components = {};
self.meta = {};
self.meta = {
activeWatchInfo: null,
accountToken: '',
watchToken: ''
};
// Let Clay handle all the magic
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
@@ -63,7 +67,7 @@ function Clay(config, customFn, options) {
* @return {void}
*/
function _populateMeta() {
self.meta = !Pebble ? {} : {
self.meta = {
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
accountToken: Pebble.getAccountToken(),
watchToken: Pebble.getWatchToken()
+17 -3
View File
@@ -255,12 +255,18 @@ describe('Clay', function() {
});
describe('.meta', function() {
var emptyMeta = {
activeWatchInfo: null,
accountToken: '',
watchToken: ''
};
it('populates the meta in the showConfiguration handler', function() {
stubPebble();
var clay = fixture.clay([]);
// meta only gets populated after showConfiguration happens
assert.deepEqual(clay.meta, {});
assert.deepEqual(clay.meta, emptyMeta);
Pebble.addEventListener.withArgs('showConfiguration').callArg(1);
assert.deepEqual(clay.meta, {
@@ -274,8 +280,8 @@ describe('Clay', function() {
stubPebble();
var clay = fixture.clay([], null, {autoHandleEvents: false});
// meta only gets populated after showConfiguration happens
assert.deepEqual(clay.meta, {});
// meta only gets populated after ready happens
assert.deepEqual(clay.meta, emptyMeta);
Pebble.addEventListener.withArgs('ready').callArg(1);
assert.deepEqual(clay.meta, {
@@ -284,6 +290,14 @@ describe('Clay', function() {
watchToken: watchToken
});
});
it('populates the meta with with empty values when there is no Pebble global',
function() {
delete global.Pebble;
var clay = fixture.clay([], null, {autoHandleEvents: false});
assert.deepEqual(clay.meta, emptyMeta);
});
});
describe('Clay.encodeDataUri()', function() {