diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0db216b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +npm-debug.log +node_modules diff --git a/package.json b/package.json index 48fa452..2ec6af7 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,9 @@ "bugs": { "url" : "https://github.com/devotis/node-extjs-custom/issues", "email" : "chris@devotis.nl" + }, + "devDependencies": { + "mocha": "2.0.x", + "should": "4.3.x" } } \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..deff38a --- /dev/null +++ b/test/test.js @@ -0,0 +1,45 @@ +var should = require('should'); + +var Ext = require('../Ext'); +Ext.Template = require('../Template'); +Ext.XTemplate = require('../XTemplate'); + +var data = { + name: 'Don Griffin', + title: 'Senior Technomage', + company: 'Sencha Inc.', + drinks: ['Coffee', 'Water', 'More Coffee'], + kids: [ + { name: 'Aubrey', age: 17 }, + { name: 'Joshua', age: 13 }, + { name: 'Cale', age: 10 }, + { name: 'Nikol', age: 5 }, + { name: 'Solomon', age: 0 } + ] +}; + +describe('Template', function() { + it('basic compiling should work', function() { + var tpl = new Ext.Template('Name: {0}, Age: {1}'); + var html = tpl.apply(['John', 25]); + html.should.be.a.String.and.be.equal('Name: John, Age: 25') + }); +}); + +describe('XTemplate', function() { + it('basic compiling should work', function() { + var tpl = new Ext.XTemplate( + '

Name: {name}

', + '

Title: {title}

', + '

Company: {company}

', + '

Kids: ', + '', // interrogate the kids property within the data + '

{name}

', + '

' + ); + + var html = tpl.apply(data); + html.should.be.a.String.and.be.equal('

Name: Don Griffin

Title: Senior Technomage

Company: Sencha Inc.

Kids:

Don Griffin

') + }); +}); +