mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-28 04:46:57 -04:00
Account for cases where the Pebble global is undefined
This commit is contained in:
Vendored
+3
-3
File diff suppressed because one or more lines are too long
@@ -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
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user