From d89fb6e83ef8b5f37b25673e80c964867f3c20fd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 27 Apr 2016 15:06:55 -0400 Subject: [PATCH] Better warning message if `defaultState` is used improperly --- app/assets/javascripts/discourse/widgets/widget.js.es6 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6 index 09c2deac3f5..31c1c3fa334 100644 --- a/app/assets/javascripts/discourse/widgets/widget.js.es6 +++ b/app/assets/javascripts/discourse/widgets/widget.js.es6 @@ -125,8 +125,11 @@ export default class Widget { this.key = this.buildKey ? this.buildKey(attrs) : null; // Helps debug widgets - if (Ember.Test) { - if (Object.keys(this.defaultState(attrs)).length > 0 && !this.key) { + if (Ember.testing) { + const ds = this.defaultState(attrs); + if (typeof ds !== "object") { + Ember.warn(`defaultState must return an object`); + } else if (Object.keys(ds).length > 0 && !this.key) { Ember.warn(`you need a key when using state ${this.name}`); } }