Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define empty state if initialState function not called #4

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/with-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ define(function (require) {
this.stateChanged = function () {};

this.after('initialize', function () {
this._stateDef = (this._stateDef || function () {});
this._stateDef = (this._stateDef || function () { return {} });
this.replaceState(this._stateDef.call(this));
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flight-with-state",
"version": "2.0.1",
"version": "2.1.0",
"devDependencies": {
"bower": "^1.3.3",
"grunt": "~0.4.5",
Expand Down
11 changes: 11 additions & 0 deletions test/spec/with-state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ define(function (require) {

var ComponentA;
var ComponentB;
var ComponentC;
var instanceAofA;
var instanceBofA;
var instanceAofB;
var instanceAofC;

// Initialize a component and attach it to the DOM
beforeEach(function () {
Expand Down Expand Up @@ -48,14 +50,18 @@ define(function (require) {
});
});

ComponentC = makeComponent(function () {});

instanceAofA = initializeComponent(ComponentA);
instanceBofA = initializeComponent(ComponentA);
instanceAofB = initializeComponent(ComponentB);
instanceAofC = initializeComponent(ComponentC);
});

afterEach(function () {
ComponentA && ComponentA.teardownAll();
ComponentB && ComponentB.teardownAll();
ComponentC && ComponentC.teardownAll();
});

describe('initialState', function () {
Expand All @@ -64,6 +70,11 @@ define(function (require) {
expect(instanceAofA.state).toBeDefined();
});

it('should add empty state if initialState is not called', function () {
expect(instanceAofC).toBeDefined();
expect(instanceAofC.state).toEqual({});
});

it('propagates initialState to this.state', function () {
expect(instanceAofA.state.alive).toBe(true);
});
Expand Down