jasmine-expect
Advanced tools
Comparing version 1.16.4 to 1.17.0
@@ -364,2 +364,17 @@ /* | ||
/** | ||
* Assert subject is string containing parseable JSON | ||
* @return {Boolean} | ||
*/ | ||
matchers.toBeJsonString = function() { | ||
var isParseable; | ||
var json; | ||
try { | ||
json = JSON.parse(this.actual); | ||
} catch (e) { | ||
isParseable = false; | ||
} | ||
return isParseable !== false && json !== null; | ||
}; | ||
/** | ||
* Assert subject is a String containing nothing but whitespace | ||
@@ -366,0 +381,0 @@ * @return {Boolean} |
{ | ||
"name": "jasmine-expect", | ||
"version": "1.16.4", | ||
"version": "1.17.0", | ||
"description": "35+ additional matchers for the Jasmine BDD JavaScript test library", | ||
@@ -5,0 +5,0 @@ "main": "jasmine-matchers.js", |
@@ -74,2 +74,3 @@ # Jasmine-Matchers | ||
expect(string).toBeHtmlString() | ||
expect(string).toBeJsonString() | ||
expect(string).toBeWhitespace() | ||
@@ -76,0 +77,0 @@ expect(string).toStartWith(substring) |
@@ -35,2 +35,17 @@ // Strings | ||
/** | ||
* Assert subject is string containing parseable JSON | ||
* @return {Boolean} | ||
*/ | ||
matchers.toBeJsonString = function() { | ||
var isParseable; | ||
var json; | ||
try { | ||
json = JSON.parse(this.actual); | ||
} catch (e) { | ||
isParseable = false; | ||
} | ||
return isParseable !== false && json !== null; | ||
}; | ||
/** | ||
* Assert subject is a String containing nothing but whitespace | ||
@@ -37,0 +52,0 @@ * @return {Boolean} |
@@ -34,2 +34,15 @@ describe('Strings', function() { | ||
describe('toBeJsonString', function () { | ||
it('asserts value is a string of parseable JSON', function () { | ||
expect('{}').toBeJsonString(); | ||
expect('[]').toBeJsonString(); | ||
expect('[1]').toBeJsonString(); | ||
expect('[1,]').not.toBeJsonString(); | ||
expect('<>').not.toBeJsonString(); | ||
expect(null).not.toBeJsonString(); | ||
expect('').not.toBeJsonString(); | ||
expect(void(0)).not.toBeJsonString(); | ||
}); | ||
}); | ||
describe('toBeWhitespace', function () { | ||
@@ -36,0 +49,0 @@ it('asserts value is a string containing only tabs, spaces, returns etc', function () { |
44670
1182
114