Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

env tests implemented & passed

  • Loading branch information...
commit ce98e9395df6d8a7aa82bcc5ac209f2ab5655ada 1 parent d5de028
@jpolo authored
Showing with 50 additions and 6 deletions.
  1. +30 −1 spec/js_spec.js
  2. +20 −5 stj.js
View
31 spec/js_spec.js
@@ -5,6 +5,35 @@ define("stj/spec/js_spec", [ "stj/spec/_base", "stj/stj" ], function () {
var module = use_("js");
describe("" + module, function () {
+ describe(".env()", function () {
+ var topic = module.env;
+ it('should be a function with 0 parameters', function () {
+ expect(topic).toBeInstanceOf(Function);
+ expect(topic).toHaveLengthOf(0);
+ });
+ it('should set/get one value', function () {
+ expect(topic('test')).toBeUndefined();
+ topic('test', 'value');
+ expect(topic('test')).toEqual('value');
+ topic('test', undefined);
+ expect(topic('test')).toBeUndefined();
+ });
+ it('should set/get many values', function () {
+ expect(topic('test1')).toBeUndefined();
+ expect(topic('test2')).toBeUndefined();
+
+ topic({
+ test1: 'value1',
+ test2: 'value2'
+ });
+ expect(topic('test1')).toEqual('value1');
+ expect(topic('test2')).toEqual('value2');
+
+ var env = topic();
+ expect(env.test1).toEqual('value1');
+ expect(env.test2).toEqual('value2');
+ });
+ });
describe(".runScript()", function () {
var topic = module.runScript;
it('should be a function with 1 parameters', function () {
@@ -24,4 +53,4 @@ define("stj/spec/js_spec", [ "stj/spec/_base", "stj/stj" ], function () {
});
});
});
-});
+});
View
25 stj.js
@@ -555,7 +555,7 @@ define("stj/stj", function () {
__def__: {
value: function __def__(stringName, objectDescriptor) {
objectDescriptor = toObject(objectDescriptor);
- stj.defineProperty(objectDescriptor.self ? this : this.prototype, stringName, objectDescriptor);//TODO remove dependency to stj?
+ stj.defineProperty(objectDescriptor.self ? this : this.prototype, stringName, objectDescriptor);
},
override: true
}
@@ -581,7 +581,7 @@ define("stj/stj", function () {
var
data = global.Env,
key = arguments[0],
- property;
+ property, value;
switch (arguments.length) {
case 0:
return data;
@@ -589,7 +589,12 @@ define("stj/stj", function () {
if (typeof key === "object") {
for (property in key) {
if (key.hasOwnProperty(property)) {
- data[property] = key[property];
+ value = key[property];
+ if (typeof value === "undefined") {
+ delete data[property];
+ } else {
+ data[property] = value;
+ }
}
}
} else {
@@ -597,14 +602,24 @@ define("stj/stj", function () {
}
break;
default:
- data[key] = arguments[1];
+ value = arguments[1];
+ if (typeof value === "undefined") {
+ delete data[key];
+ } else {
+ data[key] = value;
+ }
break;
}
return $module;
}
});
//initialize Env
- global.Env = {};
+ global.Env = {
+ /*platform: {
+ browser : typeof window !== "undefined",
+ node : typeof process !== "undefined"
+ }*/
+ };
/**
* @param {Function}
Please sign in to comment.
Something went wrong with that request. Please try again.