Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update Blueprint.

 * Change tests to use mocha
 * Add Gruntfile
 * Add Bower file
 * Fix hint
 * Update deps
 * Update API
  • Loading branch information...
commit d440290c9ab22d84ef4e1e0fa41fba080134f50c 1 parent aa3da5d
@Couto authored
View
2  .gitignore
@@ -2,3 +2,5 @@ _Store*
ehthumbs.db
Icon?
Thumbs.db
+node_modules
+coverage
View
4 .gitmodules
@@ -1,4 +0,0 @@
-[submodule "tests/vendor/qunit"]
- path = tests/vendor/qunit
- url = git://github.com/jquery/qunit.git
-
View
83 .jshintrc
@@ -0,0 +1,83 @@
+{
+
+
+ "bitwise" : true,
+ "camelcase" : true,
+ "curly" : true,
+ "eqeqeq" : true,
+ "forin" : true,
+ "immed" : true,
+ "indent" : 4,
+ "latedef" : true,
+ "newcap" : true,
+ "noarg" : true,
+ "noempty" : true,
+ "nonew" : true,
+ "plusplus" : true,
+ "quotmark" : "single",
+ "regexp" : true,
+ "undef" : true,
+ "unused" : true,
+ "strict" : false,
+ "trailing" : true,
+
+
+ "asi" : false,
+ "boss" : false,
+ "debug" : false,
+ "eqnull" : false,
+ "es5" : false,
+ "esnext" : false,
+ "evil" : false,
+ "expr" : false,
+ "funcscope" : false,
+ "globalstrict" : false,
+ "iterator" : false,
+ "lastsemic" : false,
+ "laxbreak" : false,
+ "laxcomma" : false,
+ "loopfunc" : false,
+ "multistr" : false,
+ "onecase" : false,
+ "proto" : false,
+ "regexdash" : false,
+ "scripturl" : false,
+ "smarttabs" : false,
+ "shadow" : false,
+ "sub" : false,
+ "supernew" : false,
+ "validthis" : false,
+
+
+ "browser" : true,
+ "couch" : false,
+ "devel" : false,
+ "dojo" : false,
+ "jquery" : false,
+ "mootools" : false,
+ "node" : true,
+ "nonstandard" : false,
+ "prototypejs" : false,
+ "rhino" : false,
+ "worker" : false,
+ "wsh" : false,
+
+
+ "nomen" : true,
+ "onevar" : true,
+ "passfail" : false,
+ "white" : true,
+
+ "predef" : [
+ "require",
+ "define",
+ "mocha",
+ "requirejs",
+ "describe",
+ "it",
+ "before",
+ "after",
+ "beforeAll",
+ "afterAll"
+ ]
+}
View
85 Gruntfile.js
@@ -0,0 +1,85 @@
+module.exports = function (grunt) {
+ 'use strict';
+
+ grunt.initConfig({
+ files: {
+ src: ['index.js', 'src/**/*.js'],
+ test: ['test/**/*.js'],
+ all: ['README.md', 'index.js', 'src/**/*.js', 'test/**/*.js']
+ },
+
+ jshint: {
+ files: '<%= files.all %>',
+ options: {
+ jshintrc: '.jshintrc'
+ }
+ },
+
+ uglify: {
+ dist: {
+ files: {
+ 'dist/Blueprint.min.js': ['src/Blueprint.js']
+ }
+ }
+ },
+
+ clean: {
+ coverage: ['coverage']
+ },
+
+ cafemocha: {
+
+ unit: {
+ src: '<%= files.test %>',
+ options: {
+ ui: 'exports',
+ reporter: 'nyan'
+ }
+ },
+ coverage: {
+ src: '<%= files.test %>',
+ options: {
+ ui: 'exports',
+ reporter: 'html-cov',
+ coverage: {
+ output: 'coverage/index.html',
+ env: 'BLUEPRINT_COVERAGE'
+ }
+ }
+ }
+ },
+
+ coverage: {
+ test: {
+ files: { 'coverage': 'src' }
+ }
+ }
+ });
+
+ grunt.registerMultiTask('coverage', 'Create code coverage', function () {
+ var spawn = require('child_process').spawn,
+ done = this.async(),
+ coverage = spawn('jscoverage', [this.files[0].src, this.files[0].dest]),
+ error;
+
+ coverage.stdout.on('data', function (data) {
+ console.log(data.toString());
+ });
+
+ coverage.stderr.on('data', function (data) {
+ error = new Error(data.toString());
+ });
+
+ coverage.on('close', function (code) { done(error); });
+ });
+
+ // Load Grunt Tasks
+ Object.keys(require('./package.json').devDependencies).forEach(function (key) {
+ return (/^grunt-/).test(key) && grunt.loadNpmTasks(key);
+ });
+
+ grunt.registerTask('default', ['jshint', 'cafemocha:unit']);
+ grunt.registerTask('cov', ['clean:coverage', 'coverage:test', 'cafemocha:coverage']);
+ grunt.registerTask('dist', ['default', 'uglify']);
+
+};
View
10 bower.json
@@ -0,0 +1,10 @@
+{
+ "name": "Blueprint",
+ "version": "0.0.2",
+ "main": "dist/Blueprint.min.js",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "components"
+ ]
+}
View
1  dist/Blueprint.min.js
@@ -0,0 +1 @@
+!function(a){"use strict";var b=Object.prototype.toString,c=Array.prototype.slice,d=function(){return Function.prototype.bind?function(a,b){return a.bind(b)}:function(a,b){var d=c.call(arguments,2);return function(){return a.apply(b,d.concat(c.call(arguments)))}}}(),e={create:function(a){var b,c=Object.create||function(a){function b(){}return b.prototype=a,new b};return b=c(this),a&&this.implement.call(b,a),b},implement:function(a){if(a){var b;for(b in a)a.hasOwnProperty(b)&&(this[b]=a[b])}return this},bind:function(a){var c="[object Array]"!==b.call(a)?[a]:a,e=c.length-1;for(e;e>=0;e-=1)this[c[e]]=d(this[c[e]],this);return this}};"function"==typeof define&&define.amd?define("Blueprint",[],function(){return e}):"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports?module.exports=e:a.Blueprint=e}(this);
View
3  index.js
@@ -0,0 +1,3 @@
+module.exports = (process.env.BLUEPRINT_COVERAGE) ?
+ require('./coverage/Blueprint.js') :
+ require('./src/Blueprint.js');
View
17 package.json
@@ -4,7 +4,11 @@
"description": "A simple Sugar for Prototypal Inheritance",
"version": "0.0.3",
"homepage": "http://github.com/Couto/Blueprint",
- "keywords": ["prototypal", "sugar", "blueprint"],
+ "keywords": [
+ "prototypal",
+ "sugar",
+ "blueprint"
+ ],
"repository": {
"type": "git",
"url": "git://github.com/Couto/Blueprint.git"
@@ -14,5 +18,14 @@
"node": "*"
},
"dependencies": {},
- "devDependencies": {}
+ "devDependencies": {
+ "mocha": "~1.11.0",
+ "requirejs": "~2.1.6",
+ "expect.js": "~0.2.0",
+ "grunt": "~0.4.1",
+ "grunt-cafe-mocha": "~0.1.6",
+ "grunt-contrib-clean": "~0.4.1",
+ "grunt-contrib-jshint": "~0.6.0",
+ "grunt-contrib-uglify": "~0.2.2"
+ }
}
View
79 src/Blueprint.js
@@ -33,11 +33,37 @@
* @param {Object} methods Object
* @returns Function
*/
-(function(root) {
+(function (root) {
'use strict';
- var Blueprint = {
+ var toString = Object.prototype.toString,
+ slice = Array.prototype.slice,
+
+ /**
+ * Helper method to fix the context (equivalent to ES5 Function.bind)
+ *
+ * @public
+ * @param {Function} fn Function that will be binded to the new context
+ * @param {Object} context Context
+ * @returns {Function} function proxied to the new context
+ */
+ proxy = (function () {
+ if (Function.prototype.bind) {
+ return function (fn, context) {
+ return fn.bind(context);
+ };
+ } else {
+ return function (fn, context) {
+ var args = slice.call(arguments, 2);
+ return function () {
+ return fn.apply(context, args.concat(slice.call(arguments)));
+ };
+ };
+ }
+ }()),
+
+ Blueprint = {
/**
* Creates a new instance of the current Blueprint
* if an object is given as a parameter, it will also extend
@@ -81,36 +107,23 @@
}
return this;
},
-
/**
- * Helper method to fix the context (equivalent to ES5 Function.bind)
+ * Describe what this method does
*
* @public
- * @param {Function} fn Function that will be binded to the new context
- * @param {Object} context Context
- * @returns {Function} function proxied to the new context
+ * @param {String|Object|Array|Boolean|Number} paramName Describe this parameter
+ * @returns Describe what it returns
+ * @type String|Object|Array|Boolean|Number
*/
- proxy : function(fn, context) {
- var isType = Object.prototype.toString,
- slice = Array.prototype.slice,
- tmp, args, proxy;
-
- if (isType.call(context) === '[object String]') {
- tmp = fn[context];
- context = fn;
- fn = tmp;
- }
+ bind: function (methods) {
+ var methds = toString.call(methods) !== '[object Array]' ? [methods] : methods,
+ i = methds.length - 1;
- if (isType.call(fn) !== '[object Function]') {
- return undefined;
+ for (i; i >= 0; i -= 1) {
+ this[methds[i]] = proxy(this[methds[i]], this);
}
- args = slice.call(arguments, 2);
- proxy = function () {
- return fn.apply(context, args.concat(slice.call(arguments)));
- };
-
- return proxy;
+ return this;
}
};
@@ -118,12 +131,12 @@
/**
* Expose Blueprint to the Global context with support for AMD and Node Modules
*/
- if (typeof define === "function" && define.amd) {
- define("Blueprint", [], function () { return Blueprint; } );
- } else if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports) {
- module.exports = Blueprint;
- } else {
- root.Blueprint = Blueprint;
- }
+ if (typeof define === 'function' && define.amd) {
+ define('Blueprint', [], function () { return Blueprint; });
+ } else if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports) {
+ module.exports = Blueprint;
+ } else {
+ root.Blueprint = Blueprint;
+ }
-}(this));
+}(this));
View
1  src/Blueprint.min.js
@@ -1 +0,0 @@
-(function(a){var b={create:function(a){function c(){}var b;return c.prototype=this,b=new c,a&&this.implement.call(b,a),b},implement:function(a){if(a){var b;for(b in a)a.hasOwnProperty(b)&&(this[b]=a[b])}return this},bind:function(a){var b=Object.prototype.toString.call(a)!=="[object Array]"?[a]:a,c=b.length-1;for(c;c>=0;c-=1)this[b[c]]=this.proxy(this[b[c]],this);return this},proxy:function(a,b){var c=Object.prototype.toString,d=Array.prototype.slice,e,f,g;return c.call(b)==="[object String]"&&(e=a[b],b=a,a=e),c.call(a)!=="[object Function]"?undefined:(f=d.call(arguments,2),g=function(){return a.apply(b,f.concat(d.call(arguments)))},g)}};"use strict",typeof define=="function"&&define.amd?define("Blueprint",[],function(){return b}):typeof module!="undefined"&&typeof exports!="undefined"&&module.exports?module.exports=b:a.Blueprint=b})(this);
View
20 test/config.js
@@ -0,0 +1,20 @@
+require.config({
+ paths: {
+ 'mocha' : '../node_modules/mocha/mocha',
+ 'expect': '../node_modules/expect.js/expect',
+ 'Blueprint' : '../index.js'
+ },
+ shim: {
+ 'mocha': { exports : 'mocha' },
+ 'expect': { exports : 'expect' }
+ },
+ urlArgs: 'cache=' + (+new Date())
+});
+
+require([
+ 'mocha',
+ 'expect',
+ 'instantiation.test',
+ 'parenting.test',
+ 'static.test'
+], function (mocha) { mocha.run(); });
View
83 test/index.html
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>Blueprint</title>
+ <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
+ </head>
+ <body>
+ <div id="mocha"></div>
+ <script data-main="config.js" src="../node_modules/requirejs/require.js"></script>
+ require(['Blueprint'], function(Blueprint) {
+ var base = {
+ property: "foo",
+ method1 : function () {
+ document.write("I was written with the method1 from First <br />");
+ },
+ method2 : function () {
+ document.write("I was writter with the method2 from the First <br />")
+ }
+ },
+ First = Blueprint.create(base),
+
+
+
+ Mixin = Blueprint.create({
+ mixinMethod1 : function () {
+ document.write("I was written with the mixinMethod1 from the Mixin <br />");
+ },
+ mixinMethod2 : function () {
+ document.write("I was written with the mixinMethod2 from the Mixin <br />");
+ },
+ mixinMethod3 : function () {
+ document.write("I was written with the mixinMethod3 from the Mixin <br />");
+ }
+ }),
+
+
+
+ Third = Blueprint.create({
+ method4 : function () {}
+ }).implement(Mixin),
+
+
+
+ Forth = Third.create({
+ init : function (div) {
+ div.setAttribute('id', 'example');
+ document.getElementById('qunit-fixture').appendChild(div);
+ },
+ method4 : function(){
+ document.write("I was written with the method4 from the Forth and i called the mixinMethod3 <br />");
+ this.mixinMethod3()
+ }
+ }).implement(Mixin)
+
+
+
+ third = Third.create(),
+
+
+
+ module("Instanciation Tests");
+
+
+
+
+
+
+
+ module("Parenting");
+
+
+
+
+
+
+
+
+
+ });
+ </script>
+ </body>
+</html>
View
127 test/instantiation.test.js
@@ -0,0 +1,127 @@
+define([
+ 'Blueprint',
+ 'mocha',
+ 'expect'
+], function (Blueprint, mocha, expect) {
+ 'use strict';
+
+
+ mocha.setup('bdd');
+
+ describe('Instantiation', function () {
+ var base = {
+ property: 'foo',
+ method1 : function () {
+ console.log('I was written with the method1 from First <br />');
+ },
+ method2 : function () {
+ console.log('I was writter with the method2 from the First <br />');
+ }
+ },
+ First = Blueprint.create(base),
+ first = First.create(),
+ Second = First.create({
+ method3 : function () {
+ console.log('I was written with the method3 from the Second <br />');
+ Object.getPrototypeOf(Second).method1.call(this);
+ },
+ Statics : {
+ staticFunction : function () {
+ console.log('I was written with the staticFunction from the Second <br />');
+ }
+ }
+ }),
+ Mixin = Blueprint.create({
+ mixinMethod1 : function () {
+ console.log('I was written with the mixinMethod1 from the Mixin <br />');
+ },
+ mixinMethod2 : function () {
+ console.log('I was written with the mixinMethod2 from the Mixin <br />');
+ },
+ mixinMethod3 : function () {
+ console.log('I was written with the mixinMethod3 from the Mixin <br />');
+ }
+ }),
+ Third = Blueprint.create({
+ method4 : function () {}
+ }).implement(Mixin),
+
+ Forth = Third.create({
+ init : function (div) {
+ console.log('initializer', div);
+ },
+ method4 : function () {
+ console.log('I was written with the method4 from the Forth and i called the mixinMethod3 <br />');
+ this.mixinMethod3();
+ }
+ }).implement(Mixin);
+
+ it('should match instance methods with base methods', function () {
+ expect(first.method1).to.equal(base.method1);
+ expect(first.method2).to.equal(base.method2);
+ });
+
+ it('should match instance properties with base properties', function () {
+ expect(first.property).to.equal('foo');
+ });
+
+ it('should match instance method with prototype methods', function () {
+ expect(first.method1).to.equal(Object.getPrototypeOf(First).method1);
+ expect(first.method2).to.equal(Object.getPrototypeOf(First).method2);
+ expect(first.property).to.equal(Object.getPrototypeOf(First).property);
+ });
+
+
+ it('should have methods from Class and extended Class', function () {
+ var second = Second.create();
+ expect(second.method3, Object.getPrototypeOf(Second).method3, 'Instanciated Object has method from Class child');
+ expect(second.method2, base.method2, 'Instanciated Object has method from base Object');
+ expect(second.method1, base.method1, 'Instanciated Object has method from base Object');
+ expect(second.property, base.property, 'Instanciated Object has property from base Object');
+ expect(second.method2, Object.getPrototypeOf(First).method2, 'Instanciated Object has method from extended Class');
+ expect(second.method1, Object.getPrototypeOf(First).method1, 'Instanciated Object has method from extended Class');
+ expect(second.property, Object.getPrototypeOf(First).property, 'Instanciated Object has property from extended Class');
+ expect(7);
+ });
+
+
+
+ it('should call initialize at instanciation time', function () {
+ var div = document.createElement('div'),
+ allocatedDiv = document.getElementById('example');
+
+ expect(Forth.create().init(div), allocatedDiv, 'Object was in the DOM meaning that init ran at initialization');
+ expect(1);
+ });
+
+ it('should have mixin\'s methods', function () {
+ var third = Third.create();
+ expect(third.mixinMethod1, Object.getPrototypeOf(Mixin).mixinMethod1, 'Class inherited Mixin\'s method');
+ expect(third.mixinMethod2, Object.getPrototypeOf(Mixin).mixinMethod2, 'Class inherited Mixin\'s method');
+ expect(third.mixinMethod3, Object.getPrototypeOf(Mixin).mixinMethod3, 'Class inherited Mixin\'s method');
+ expect(third.method4, Object.getPrototypeOf(Third).method4, 'Class remain with it\'s own method');
+ expect(4);
+ });
+
+ it('should have mixins methods', function () {
+ var mixinObj = {
+ mixinObjMethod1 : function () {},
+ mixinObjMethod2 : function () {},
+ mixinObjMethod3 : function () {}
+ },
+ Fifth = Blueprint.create({
+ method1 : function () {},
+ method2 : function () {}
+ }).implement(mixinObj),
+ fifth = Fifth.create();
+
+ expect(mixinObj.mixinObjMethod1).to.equal(fifth.mixinObjMethod1);
+ expect(mixinObj.mixinObjMethod2).to.equal(fifth.mixinObjMethod2);
+ expect(mixinObj.mixinObjMethod3).to.equal(fifth.mixinObjMethod3);
+ expect(fifth.method1).to.equal(Object.getPrototypeOf(Fifth).method1);
+
+ });
+
+ });
+
+});
View
40 test/parenting.test.js
@@ -0,0 +1,40 @@
+define([
+ 'Blueprint',
+ 'mocha',
+ 'expect'
+], function (Blueprint, mocha, expect) {
+ 'use strict';
+
+ mocha.setup('bdd');
+
+ describe('Parenting', function () {
+ var base = {
+ property: 'foo',
+ method1 : function () {
+ console.log('I was written with the method1 from First <br />');
+ },
+ method2 : function () {
+ console.log('I was writter with the method2 from the First <br />');
+ }
+ },
+ First = Blueprint.create(base),
+
+ Second = First.create({
+ method3 : function () {
+ console.log('I was written with the method3 from the Second <br />');
+ Object.getPrototypeOf(Second).method1.call(this);
+ },
+ Statics : {
+ staticFunction : function () {
+ console.log('I was written with the staticFunction from the Second <br />');
+ }
+ }
+ });
+
+
+ it('should have access to it\'s parent', function () {
+ expect(Second.Parent).to.equal(First.prototype);
+ });
+ });
+
+});
View
43 test/static.test.js
@@ -0,0 +1,43 @@
+define([
+ 'Blueprint',
+ 'mocha',
+ 'expect'
+], function (Blueprint, mocha, expect) {
+
+ 'use strict';
+
+ mocha.setup('bdd');
+
+ describe('Static methods', function () {
+
+ var base = {
+ property: 'foo',
+ method1 : function () {
+ console.log('I was written with the method1 from First <br />');
+ },
+ method2 : function () {
+ console.log('I was writter with the method2 from the First <br />');
+ }
+ },
+ First = Blueprint.create(base),
+ Second = First.create({
+ method3 : function () {
+ console.log('I was written with the method3 from the Second <br />');
+ Object.getPrototypeOf(Second).method1.call(this);
+ },
+ Statics : {
+ staticFunction : function () {
+ console.log('I was written with the staticFunction from the Second <br />');
+ }
+ }
+ });
+
+ it('should be accessible', function () {
+ var second = Second.create();
+ console.dir(Second);
+ console.dir(second);
+ expect(Second.staticFunction).not.to.equal(undefined);
+ });
+ });
+
+});
View
174 tests/index.html
@@ -1,174 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>Blueprint - Tests Page</title>
- <link rel="stylesheet" href="vendor/qunit/qunit/qunit.css">
- <script type="text/javascript" charset="utf-8" src="vendor/qunit/qunit/qunit.js"></script>
- <script type="text/javascript" charset="utf-8" src="../src/Blueprint.js"></script>
- </head>
- <body>
- <h1 id="qunit-header">Blueprint's Unit Tests</h1>
- <h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
- <h2 id="qunit-userAgent"></h2>
- <ol id="qunit-tests"></ol>
- <div id="qunit-fixture">test markup, will be hidden</div>
- <script>
- var base = {
- property: "foo",
- method1 : function () {
- document.write("I was written with the method1 from First <br />");
- },
- method2 : function () {
- document.write("I was writter with the method2 from the First <br />")
- }
- },
- First = Blueprint.create(base),
-
- Second = First.create({
- method3 : function(){
- document.write("I was written with the method3 from the Second <br />");
- Object.getPrototypeOf(Second).method1.call(this);
- },
- Statics : {
- staticFunction : function () {
- document.write("I was written with the staticFunction from the Second <br />");
- }
- }
- }),
-
-
- Mixin = Blueprint.create({
- mixinMethod1 : function () {
- document.write("I was written with the mixinMethod1 from the Mixin <br />");
- },
- mixinMethod2 : function () {
- document.write("I was written with the mixinMethod2 from the Mixin <br />");
- },
- mixinMethod3 : function () {
- document.write("I was written with the mixinMethod3 from the Mixin <br />");
- }
- }),
-
-
-
- Third = Blueprint.create({
- method4 : function () {}
- }).implement(Mixin),
-
-
-
- Forth = Third.create({
- init : function (div) {
- div.setAttribute('id', 'example');
- document.getElementById('qunit-fixture').appendChild(div);
- },
- method4 : function(){
- document.write("I was written with the method4 from the Forth and i called the mixinMethod3 <br />");
- this.mixinMethod3()
- }
- }).implement(Mixin)
-
-
-
- third = Third.create(),
-
-
-
- module("Instanciation Tests");
-
-
-
- test("Instanciated Object should have Class methods and Properties", function() {
- var first = First.create();
- console.log("first => ", first);
- console.log("First => ", First)
- equal(first.method1, base.method1, "Instanciated Object has method from base Object");
- equal(first.method2, base.method2, "Instanciated Object has method from base Object");
- equal(first.property, 'foo', "Instanciated Object has property from base Object");
- equal(first.method1, Object.getPrototypeOf(First).method1, "Instanciated Object has method from Class prototype");
- equal(first.method2, Object.getPrototypeOf(First).method2, "Instanciated Object has method from Class prototype");
- equal(first.property, Object.getPrototypeOf(First).property, "Instanciated Object has property from Class prototype");
- expect(6)
- });
-
-
-
- test("Class extending a Class, should have methods from Class and extended Class", function(){
- var second = Second.create();
- equal(second.method3, Object.getPrototypeOf(Second).method3, "Instanciated Object has method from Class child");
- equal(second.method2, base.method2, "Instanciated Object has method from base Object");
- equal(second.method1, base.method1, "Instanciated Object has method from base Object");
- equal(second.property, base.property, "Instanciated Object has property from base Object");
- equal(second.method2, Object.getPrototypeOf(First).method2, "Instanciated Object has method from extended Class");
- equal(second.method1, Object.getPrototypeOf(First).method1, "Instanciated Object has method from extended Class");
- equal(second.property, Object.getPrototypeOf(First).property, "Instanciated Object has property from extended Class");
- expect(7);
- });
-
-
-
- test("Class with defined initialize should run at instanciation time", function(){
- var div = document.createElement('div'),
- forth = Forth.create().init(div),
- allocatedDiv = document.getElementById('example');
-
- equal(div, allocatedDiv, "Object was in the DOM meaning that init ran at initialization");
- expect(1);
- });
-
-
-
- test("Class with declared Mixins, should have mixin's methods", function(){
- var third = Third.create();
- equal(third.mixinMethod1, Object.getPrototypeOf(Mixin).mixinMethod1, 'Class inherited Mixin\'s method');
- equal(third.mixinMethod2, Object.getPrototypeOf(Mixin).mixinMethod2, 'Class inherited Mixin\'s method');
- equal(third.mixinMethod3, Object.getPrototypeOf(Mixin).mixinMethod3, 'Class inherited Mixin\'s method');
- equal(third.method4, Object.getPrototypeOf(Third).method4, 'Class remain with it\'s own method');
- expect(4);
- });
-
- test("Class using plain object as mixins, should have mixins methods", function(){
- var mixinObj = {
- mixinObjMethod1 : function(){},
- mixinObjMethod2 : function(){},
- mixinObjMethod3 : function(){},
- },
- Fifth = Blueprint.create({
- method1 : function(){},
- method2 : function(){}
- }).implement(mixinObj),
- fifth = Fifth.create();
- console.log(fifth);
- equal(mixinObj.mixinObjMethod1, fifth.mixinObjMethod1, 'Class inherited Mixin\'s method');
- equal(mixinObj.mixinObjMethod2, fifth.mixinObjMethod2, 'Class inherited Mixin\'s method');
- equal(mixinObj.mixinObjMethod3, fifth.mixinObjMethod3, 'Class inherited Mixin\'s method');
- equal(fifth.method1, Object.getPrototypeOf(Fifth).method1, 'Class remain with it\'s own method');
- expect(4);
- });
-
-
-
- module("Parenting");
-
-
-
- test("Class should have access to it's parent", function(){
- var second = Second.create();
- equal(Second.Parent, First.prototype, 'It can access it\'s parent');
- });
-
-
-
- module("Static Methods");
-
-
-
- test("Static methods should be accessible", function(){
- notEqual(Second.staticFunction, undefined, "Static methods are acessible")
- });
-
- </script>
- </body>
-</html>
View
183 tests/index_amd.html
@@ -1,183 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
- <title>Blueprint - Tests Page</title>
- <link rel="stylesheet" href="vendor/qunit/qunit/qunit.css">
- <script type="text/javascript" charset="utf-8" src="vendor/qunit/qunit/qunit.js"></script>
- <script type="text/javascript" charset="utf-8" src="http://requirejs.org/docs/release/1.0.4/minified/require.js"></script>
- </head>
- <body>
- <h1 id="qunit-header">Blueprint's Unit Tests</h1>
- <h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
- <h2 id="qunit-userAgent"></h2>
- <ol id="qunit-tests"></ol>
- <div id="qunit-fixture">test markup, will be hidden</div>
- <script>
- require.config({
- paths: {
- "Blueprint" : "../src/Blueprint"
- },
- urlArgs: "cache=" + (+new Date())
- });
- require(['Blueprint'], function(Blueprint) {
- var base = {
- property: "foo",
- method1 : function () {
- document.write("I was written with the method1 from First <br />");
- },
- method2 : function () {
- document.write("I was writter with the method2 from the First <br />")
- }
- },
- First = Blueprint.create(base),
-
- Second = First.create({
- method3 : function(){
- document.write("I was written with the method3 from the Second <br />");
- Object.getPrototypeOf(Second).method1.call(this);
- },
- Statics : {
- staticFunction : function () {
- document.write("I was written with the staticFunction from the Second <br />");
- }
- }
- }),
-
-
- Mixin = Blueprint.create({
- mixinMethod1 : function () {
- document.write("I was written with the mixinMethod1 from the Mixin <br />");
- },
- mixinMethod2 : function () {
- document.write("I was written with the mixinMethod2 from the Mixin <br />");
- },
- mixinMethod3 : function () {
- document.write("I was written with the mixinMethod3 from the Mixin <br />");
- }
- }),
-
-
-
- Third = Blueprint.create({
- method4 : function () {}
- }).implement(Mixin),
-
-
-
- Forth = Third.create({
- init : function (div) {
- div.setAttribute('id', 'example');
- document.getElementById('qunit-fixture').appendChild(div);
- },
- method4 : function(){
- document.write("I was written with the method4 from the Forth and i called the mixinMethod3 <br />");
- this.mixinMethod3()
- }
- }).implement(Mixin)
-
-
-
- third = Third.create(),
-
-
-
- module("Instanciation Tests");
-
-
-
- test("Instanciated Object should have Class methods and Properties", function() {
- var first = First.create();
- console.log("first => ", first);
- console.log("First => ", First)
- equal(first.method1, base.method1, "Instanciated Object has method from base Object");
- equal(first.method2, base.method2, "Instanciated Object has method from base Object");
- equal(first.property, 'foo', "Instanciated Object has property from base Object");
- equal(first.method1, Object.getPrototypeOf(First).method1, "Instanciated Object has method from Class prototype");
- equal(first.method2, Object.getPrototypeOf(First).method2, "Instanciated Object has method from Class prototype");
- equal(first.property, Object.getPrototypeOf(First).property, "Instanciated Object has property from Class prototype");
- expect(6)
- });
-
-
-
- test("Class extending a Class, should have methods from Class and extended Class", function(){
- var second = Second.create();
- equal(second.method3, Object.getPrototypeOf(Second).method3, "Instanciated Object has method from Class child");
- equal(second.method2, base.method2, "Instanciated Object has method from base Object");
- equal(second.method1, base.method1, "Instanciated Object has method from base Object");
- equal(second.property, base.property, "Instanciated Object has property from base Object");
- equal(second.method2, Object.getPrototypeOf(First).method2, "Instanciated Object has method from extended Class");
- equal(second.method1, Object.getPrototypeOf(First).method1, "Instanciated Object has method from extended Class");
- equal(second.property, Object.getPrototypeOf(First).property, "Instanciated Object has property from extended Class");
- expect(7);
- });
-
-
-
- test("Class with defined initialize should run at instanciation time", function(){
- var div = document.createElement('div'),
- forth = Forth.create().init(div),
- allocatedDiv = document.getElementById('example');
-
- equal(div, allocatedDiv, "Object was in the DOM meaning that init ran at initialization");
- expect(1);
- });
-
-
-
- test("Class with declared Mixins, should have mixin's methods", function(){
- var third = Third.create();
- equal(third.mixinMethod1, Object.getPrototypeOf(Mixin).mixinMethod1, 'Class inherited Mixin\'s method');
- equal(third.mixinMethod2, Object.getPrototypeOf(Mixin).mixinMethod2, 'Class inherited Mixin\'s method');
- equal(third.mixinMethod3, Object.getPrototypeOf(Mixin).mixinMethod3, 'Class inherited Mixin\'s method');
- equal(third.method4, Object.getPrototypeOf(Third).method4, 'Class remain with it\'s own method');
- expect(4);
- });
-
- test("Class using plain object as mixins, should have mixins methods", function(){
- var mixinObj = {
- mixinObjMethod1 : function(){},
- mixinObjMethod2 : function(){},
- mixinObjMethod3 : function(){},
- },
- Fifth = Blueprint.create({
- method1 : function(){},
- method2 : function(){}
- }).implement(mixinObj),
- fifth = Fifth.create();
- console.log(fifth);
- equal(mixinObj.mixinObjMethod1, fifth.mixinObjMethod1, 'Class inherited Mixin\'s method');
- equal(mixinObj.mixinObjMethod2, fifth.mixinObjMethod2, 'Class inherited Mixin\'s method');
- equal(mixinObj.mixinObjMethod3, fifth.mixinObjMethod3, 'Class inherited Mixin\'s method');
- equal(fifth.method1, Object.getPrototypeOf(Fifth).method1, 'Class remain with it\'s own method');
- expect(4);
- });
-
-
-
- module("Parenting");
-
-
-
- test("Class should have access to it's parent", function(){
- var second = Second.create();
- equal(Second.Parent, First.prototype, 'It can access it\'s parent');
- });
-
-
-
- module("Static Methods");
-
-
-
- test("Static methods should be accessible", function(){
- notEqual(Second.staticFunction, undefined, "Static methods are acessible")
- });
-
-
- });
- </script>
- </body>
-</html>
1  tests/vendor/qunit
@@ -1 +0,0 @@
-Subproject commit 24a8f2b90a0c30b8e3f87a2d685ad57dd66f4708
Please sign in to comment.
Something went wrong with that request. Please try again.