Permalink
Browse files

initial work on some best practices tests

  • Loading branch information...
1 parent 6a9cb4c commit e79d4882132f20f2ef5e682568a0f0e09ce3e349 @rmurphey committed Jul 31, 2012
Showing with 67 additions and 0 deletions.
  1. +36 −0 app/bestPractices.js
  2. +30 −0 tests/app/bestPractices.js
  3. +1 −0 tests/runner.js
View
@@ -0,0 +1,36 @@
+if (typeof define !== 'function') { var define = require('amdefine')(module); }
+
+/**
+ * This file defines an object with some methods. Some of these methods are
+ * populated incorrectly; your job is to fix them. Other methods are not
+ * populated at all; your job is to fill them out.
+ */
+define(function() {
+ return {
+ globals : function() {
+ myObject = {
+ name : 'Jory'
+ };
+
+ return myObject;
+ },
+
+ functions : function(flag) {
+ if (flag) {
+ function getValue() { return "a"; }
+ } else {
+ function getValue() { return "b"; }
+ }
+
+ return getValue();
+ },
+
+ parseInt : function(num) {
+ return parseInt(num);
+ },
+
+ identity : function(val1, val2) {
+
+ }
+ };
+});
View
@@ -0,0 +1,30 @@
+if (typeof define !== 'function') { var define = require('amdefine')(module); }
+
+define([
+ 'app/bestPractices'
+], function(answers) {
+ describe("best practices", function(){
+ it("you should avoid global variables", function() {
+ answers.globals();
+ expect(window.myObject).not.to.be.ok();
+ });
+
+ it("you should declare functions safely", function() {
+ var val = answers.functions(true);
+ expect(val).to.be('a');
+ });
+
+ it("you should use parseInt correctly", function() {
+ expect(answers.parseInt('12')).to.be(12);
+ expect(answers.parseInt('12px')).to.be(12);
+ expect(answers.parseInt('012')).to.be(12);
+ });
+
+ it("you should understand strict comparison", function() {
+ expect(answers.identity(1, '1')).to.be(false);
+ expect(answers.identity(1, 1)).to.be(true);
+ expect(answers.identity(0, false)).to.be(false);
+ });
+
+ });
+});
View
@@ -1,5 +1,6 @@
var tests = [
// link to test files here
+ 'tests/app/bestPractices',
'tests/app/arrays',
'tests/app/objects',
'tests/app/functions',

0 comments on commit e79d488

Please sign in to comment.