Skip to content

Commit

Permalink
Specs: Adapt a bunch of specs to either work or be skipped in a serve…
Browse files Browse the repository at this point in the history
…r environment.
  • Loading branch information
timwienk committed Sep 27, 2015
1 parent 5b602a4 commit ca03040
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Specs/Class/Class.Extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ describe('Options Class with Events', function(){

describe('setOptions', function(){

it('should allow to pass the document', function(){
var dit = (typeof document === 'undefined' ? xit : it);
dit('should allow to pass the document', function(){

var A = new Class({

Expand Down
8 changes: 5 additions & 3 deletions Specs/Class/Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,24 @@ describe('Class.toElement', function(){

});

it('should return an element when a class instance is passed to document.id', function(){
var dit = (typeof Element === 'undefined' ? xit : it);

dit('should return an element when a class instance is passed to document.id', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyParentElement(element);

expect(document.id(instance)).toBe(element);
});

it('should call the toElement() method in parent class if none is defined in child', function(){
dit('should call the toElement() method in parent class if none is defined in child', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyChildElement(element);

expect(document.id(instance)).toBe(element);
expect(instance instanceof MyParentElement).toEqual(true);
});

it('should call toElement() when extending natives (String, Array, Object)', function(){
dit('should call toElement() when extending natives (String, Array, Object)', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyArrayElement(element);

Expand Down
7 changes: 6 additions & 1 deletion Specs/Types/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ describe("Array", function(){

// Array.link
it('should link an array items to a new object according to the specified matchers', function(){
var el = document.createElement('div');
if (typeof document === 'undefined'){
var el = {$family: function(){ return 'element'; }};
} else {
var el = document.createElement('div');
}

var assoc2 = [100, 'Hello', {foo: 'bar'}, el, false].link({
myNumber: isType('number'),
myElement: isType('element'),
Expand Down
8 changes: 6 additions & 2 deletions Specs/Types/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,21 @@ describe("Function Methods", function(){
// Function.delay

it('delay should return a timer pointer', function(){
var referenceTimer = setTimeout(function(){}, 10000);
var timer = (function(){}).delay(10000);
expect(typeOf(timer) == 'number').toBeTruthy();
expect(typeOf(timer)).toEqual(typeOf(referenceTimer));
clearTimeout(timer);
clearTimeout(referenceTimer);
});

// Function.periodical

it('periodical should return a timer pointer', function(){
var referenceTimer = setInterval(function(){}, 10000);
var timer = (function(){}).periodical(10000);
expect(typeOf(timer) == 'number').toBeTruthy();
expect(typeOf(timer)).toEqual(typeOf(referenceTimer));
clearInterval(timer);
clearInterval(referenceTimer);
});

});
Expand Down
3 changes: 2 additions & 1 deletion Specs/Types/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ describe('Object.getLength', function(){

describe('Object hasOwnProperty', function(){

it('should not fail on window', function(){
var dit = (typeof window === 'undefined' ? xit : it);
dit('should not fail on window', function(){
expect(function(){
var fn = function(){};
Object.each(window, fn);
Expand Down
13 changes: 7 additions & 6 deletions Specs/Utilities/JSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('JSON', function(){
});
describe('JSON', function(){

var win = (typeof window === 'undefined' ? global : window);
var goodString = '{"name":"Jim Cowart","location":{"city":{"name":"Chattanooga","population":167674}}}';
var badString = 'alert("I\'m a bad string!")';

Expand All @@ -45,23 +46,23 @@ describe('JSON', function(){
});

it('should parse a hazarous string when secure is set to false', function(){
var _old_alert = window.alert;
window.alert = function (string) {
var _old_alert = win.alert;
win.alert = function (string) {
if (string == "I'm a bad string!") return true;
return false;
};
expect(JSON.decode(badString, false)).toEqual(true);
window.alert = _old_alert;
win.alert = _old_alert;
});
it('should parse a hazarous string when JSON.secure is set to false and secure is not defined', function(){
var _old_alert = window.alert;
window.alert = function (string) {
var _old_alert = win.alert;
win.alert = function (string) {
if (string == "I'm a bad string!") return true;
return false;
};
JSON.secure = false;
expect(JSON.decode(badString)).toEqual(true);
window.alert = _old_alert;
win.alert = _old_alert;
JSON.secure = true;
});
it('should NOT parse a hazarous string by default', function(){
Expand Down

0 comments on commit ca03040

Please sign in to comment.