Skip to content

Commit

Permalink
Initial commit of browser testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kirk7880 committed Sep 3, 2014
1 parent eaee591 commit 08b84bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* jshint unused:false */
(function() {
(function(root) {
'use strict';

var jsonPromise = {};
var root = this;
var previous = root.jsonPromise || null;

var isNode = (typeof require !== 'undefined' && typeof module !== 'undefined' && module.exports);
Expand Down Expand Up @@ -45,7 +44,7 @@

exports.jsonPromise = jsonPromise;
} else if (isAMD) {
define([], function() {
define(function() {
return jsonPromise;
});
} else {
Expand All @@ -56,4 +55,4 @@
root.jsonPromise = previous;
return jsonPromise;
};
}).call(this);
})(this);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"mocha-istanbul": "*",
"coveralls": "*",
"mocha-lcov-reporter": "*",
"jshint": "2.x.x"
"jshint": "2.x.x",
"chai": "*"
},
"keywords": [
"json",
Expand Down
15 changes: 8 additions & 7 deletions test/test-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ var parser = require('../index');
var validObject = require(__dirname + '/fixtures/valid-object');
var validString = require(__dirname + '/fixtures/valid-string');
var invalidString = require(__dirname + '/fixtures/invalid-string');
var assert = require("assert");
var chai = require('chai');
var expect = chai.expect;

describe('parser.parse', function(){
it('validObject should should be an object', function(done){
assert.equal(typeof {}, typeof validObject);
expect(typeof validObject).to.equal(typeof {});
done();
});

it('validString should should be a string', function(done){
assert.equal(typeof "", typeof validString);
expect(typeof validString).to.equal(typeof "");
done();
});

it('invalid should should be a string', function(done){
assert.equal(typeof "", typeof invalidString);
expect(typeof invalidString).to.equal(typeof "");
done();
});

it('should return JSON object that is already an object successfully', function(done){
parser.parse(validObject).then(function(data) {
assert.equal((typeof {}), typeof data);
expect(typeof data).to.equal(typeof {});
done();
}).catch(function(e) {
throw e;
Expand All @@ -33,7 +34,7 @@ describe('parser.parse', function(){

it('should return JSON Object that is converted to a string successfully', function(done){
parser.parse(validString).then(function(data) {
assert.equal((typeof {}), typeof data);
expect(typeof data).to.equal(typeof {});
done();
}).catch(function(e) {
throw e;
Expand All @@ -45,7 +46,7 @@ describe('parser.parse', function(){
parser.parse(invalidString).then(function() {
throw new Error('This test should have failed!');
}).catch(function(e) {
assert.equal(true, e instanceof Error);
expect((e instanceof Error)).to.equal(true);
done();
});
});
Expand Down
15 changes: 8 additions & 7 deletions test/test-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ var parser = require('../index');
var validObject = require(__dirname + '/fixtures/valid-object');
var validString = require(__dirname + '/fixtures/valid-string');
var invalidString = require(__dirname + '/fixtures/invalid-string');
var assert = require("assert");
var chai = require('chai');
var expect = chai.expect;

describe('parser.stringify', function(){
it('validObject should should be an object', function(done){
assert.equal(typeof {}, typeof validObject);
expect(typeof validObject).to.equal(typeof {});
done();
});

it('validString should should be a string', function(done){
assert.equal(typeof "", typeof validString);
expect(typeof validString).to.equal(typeof "");
done();
});

it('invalid should should be a string', function(done){
assert.equal(typeof "", typeof invalidString);
expect(typeof validString).to.equal(typeof "");
done();
});

it('should return JSON string from a JSON object', function(done){
parser.stringify(validObject).then(function(data) {
assert.equal((typeof ""), typeof data);
expect(typeof data).to.equal(typeof "");
done();
}).catch(function(e) {
throw e;
Expand All @@ -33,7 +34,7 @@ describe('parser.stringify', function(){

it('should return JSON string that is already a JSON string', function(done){
parser.stringify(validString).then(function(data) {
assert.equal((typeof ""), typeof data);
expect(typeof data).to.equal(typeof "");
done();
}).catch(function(e) {
throw e;
Expand All @@ -45,7 +46,7 @@ describe('parser.stringify', function(){
parser.stringify(invalidString).then(function() {
throw new Error('This test should have failed!');
}).catch(function(e) {
assert.equal(true, e instanceof Error);
expect(e instanceof Error).to.equal(true);
done();
});
});
Expand Down

0 comments on commit 08b84bc

Please sign in to comment.