mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-06 00:57:21 -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.config = config;
|
||||||
self.customFn = customFn || function() {};
|
self.customFn = customFn || function() {};
|
||||||
self.components = {};
|
self.components = {};
|
||||||
self.meta = {};
|
self.meta = {
|
||||||
|
activeWatchInfo: null,
|
||||||
|
accountToken: '',
|
||||||
|
watchToken: ''
|
||||||
|
};
|
||||||
|
|
||||||
// Let Clay handle all the magic
|
// Let Clay handle all the magic
|
||||||
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
|
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
|
||||||
@@ -63,7 +67,7 @@ function Clay(config, customFn, options) {
|
|||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function _populateMeta() {
|
function _populateMeta() {
|
||||||
self.meta = !Pebble ? {} : {
|
self.meta = {
|
||||||
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
|
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
|
||||||
accountToken: Pebble.getAccountToken(),
|
accountToken: Pebble.getAccountToken(),
|
||||||
watchToken: Pebble.getWatchToken()
|
watchToken: Pebble.getWatchToken()
|
||||||
|
|||||||
+17
-3
@@ -255,12 +255,18 @@ describe('Clay', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('.meta', function() {
|
describe('.meta', function() {
|
||||||
|
var emptyMeta = {
|
||||||
|
activeWatchInfo: null,
|
||||||
|
accountToken: '',
|
||||||
|
watchToken: ''
|
||||||
|
};
|
||||||
|
|
||||||
it('populates the meta in the showConfiguration handler', function() {
|
it('populates the meta in the showConfiguration handler', function() {
|
||||||
stubPebble();
|
stubPebble();
|
||||||
var clay = fixture.clay([]);
|
var clay = fixture.clay([]);
|
||||||
|
|
||||||
// meta only gets populated after showConfiguration happens
|
// meta only gets populated after showConfiguration happens
|
||||||
assert.deepEqual(clay.meta, {});
|
assert.deepEqual(clay.meta, emptyMeta);
|
||||||
Pebble.addEventListener.withArgs('showConfiguration').callArg(1);
|
Pebble.addEventListener.withArgs('showConfiguration').callArg(1);
|
||||||
|
|
||||||
assert.deepEqual(clay.meta, {
|
assert.deepEqual(clay.meta, {
|
||||||
@@ -274,8 +280,8 @@ describe('Clay', function() {
|
|||||||
stubPebble();
|
stubPebble();
|
||||||
var clay = fixture.clay([], null, {autoHandleEvents: false});
|
var clay = fixture.clay([], null, {autoHandleEvents: false});
|
||||||
|
|
||||||
// meta only gets populated after showConfiguration happens
|
// meta only gets populated after ready happens
|
||||||
assert.deepEqual(clay.meta, {});
|
assert.deepEqual(clay.meta, emptyMeta);
|
||||||
Pebble.addEventListener.withArgs('ready').callArg(1);
|
Pebble.addEventListener.withArgs('ready').callArg(1);
|
||||||
|
|
||||||
assert.deepEqual(clay.meta, {
|
assert.deepEqual(clay.meta, {
|
||||||
@@ -284,6 +290,14 @@ describe('Clay', function() {
|
|||||||
watchToken: watchToken
|
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() {
|
describe('Clay.encodeDataUri()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user