chai-uuid
Advanced tools
Comparing version 1.0.4 to 1.0.5
15
index.js
'use strict'; | ||
module.exports = function (chai, utils) { | ||
const Assertion = chai.Assertion; | ||
var Assertion = chai.Assertion; | ||
var assert = chai.assert; | ||
@@ -34,3 +35,3 @@ /** | ||
function uuid(version) { | ||
const v = (version) ? version : ''; | ||
var v = (version) ? version : ''; | ||
@@ -47,3 +48,3 @@ // verify its a valid string | ||
// assert it is a valid uuid | ||
const regex = getRegEx(v); | ||
var regex = getRegEx(v); | ||
this.assert( | ||
@@ -56,5 +57,11 @@ regex.test(this._obj), | ||
// expose methods for chai | ||
// should / expect methods for chai | ||
Assertion.addMethod('uuid', uuid) | ||
Assertion.addMethod('guid', uuid) | ||
// assert methods for chai | ||
assert.uuid = function (val, exp) { | ||
new chai.Assertion(val).to.be.a.uuid(exp); | ||
}; | ||
assert.guid = assert.uuid; | ||
}; |
{ | ||
"name": "chai-uuid", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Chai plugin for performing assertions on UUIDs", | ||
@@ -22,3 +22,5 @@ "main": "index.js", | ||
"should", | ||
"guid" | ||
"guid", | ||
"chai-plugin", | ||
"browser" | ||
], | ||
@@ -25,0 +27,0 @@ "author": "Ryan French <frenchrya@gmail.com> (https://github.com/rfrench)", |
@@ -1,8 +0,10 @@ | ||
const chai = require('chai'); | ||
var chai = require('chai'); | ||
chai.use(require('../index')); | ||
const expect = chai.expect; | ||
var expect = chai.expect; | ||
var should = chai.should(); | ||
var assert = chai.assert; | ||
describe('Validate UUID', () => { | ||
describe('Validate UUID', function(){ | ||
describe('Any Version', function() { | ||
const uuid = '8becb83e-7125-1488-b56d-af27d19d313e'; | ||
var uuid = '8becb83e-7125-1488-b56d-af27d19d313e'; | ||
@@ -20,6 +22,18 @@ it('should successfully validate a UUID (any version)', function() { | ||
}); | ||
it('should successfully validate a UUID (any version) using "should" style testing', function() { | ||
uuid.should.be.a.uuid('v1'); | ||
}); | ||
it('should successfully validate a UUID (any version) using "assert" style testing', function() { | ||
assert.uuid(uuid, 'v1'); | ||
}); | ||
it('should successfully validate a GUID (any version) using "assert" style testing', function() { | ||
assert.guid(uuid, 'v1'); | ||
}); | ||
}); | ||
describe('V1', function() { | ||
const v1 = '6866b356-4d73-11e7-b114-b2f933d5fe66'; | ||
var v1 = '6866b356-4d73-11e7-b114-b2f933d5fe66'; | ||
@@ -35,3 +49,3 @@ it('should successfully validate a v1 UUID', function() { | ||
it('should fail to validate an v1 UUID when the UUID is v4', function() { | ||
const v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
var v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
try { | ||
@@ -47,3 +61,3 @@ expect(v4).to.be.a.uuid('v1'); | ||
describe('V2', function() { | ||
const v2 = 'cd4c9471-832c-274b-828b-0208b26cc132'; | ||
var v2 = 'cd4c9471-832c-274b-828b-0208b26cc132'; | ||
@@ -59,3 +73,3 @@ it('should successfully validate a v2 UUID', function() { | ||
it('should fail to validate an v2 UUID when the UUID is v4', function() { | ||
const v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
var v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
try { | ||
@@ -71,3 +85,3 @@ expect(v4).to.be.a.uuid('v2'); | ||
describe('V3', function() { | ||
const v3 = 'df4efe51-9457-3f35-875d-df5821afcdbf'; | ||
var v3 = 'df4efe51-9457-3f35-875d-df5821afcdbf'; | ||
@@ -83,3 +97,3 @@ it('should successfully validate a v3 UUID', function() { | ||
it('should fail to validate an v3 UUID when the UUID is v4', function() { | ||
const v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
var v4 = '6000ad5c-5f8e-43f6-ba09-fba7e844a674'; | ||
try { | ||
@@ -95,3 +109,3 @@ expect(v4).to.be.a.uuid('v3'); | ||
describe('V4', function() { | ||
const v4 = '94126908-4b30-47c1-bc56-1d39e2c3334f'; | ||
var v4 = '94126908-4b30-47c1-bc56-1d39e2c3334f'; | ||
@@ -107,3 +121,3 @@ it('should successfully validate a v4 UUID', function() { | ||
it('should fail to validate an v4 UUID when the UUID is v1', function() { | ||
const v1 = '6000ad5c-5f8e-13f6-ba09-fba7e844a674'; | ||
var v1 = '6000ad5c-5f8e-13f6-ba09-fba7e844a674'; | ||
try { | ||
@@ -119,3 +133,3 @@ expect(v1).to.be.a.uuid('v4'); | ||
describe('V5', function() { | ||
const v5 = '511ff25d-ca33-536e-89a7-d3dfebc23e2a'; | ||
var v5 = '511ff25d-ca33-536e-89a7-d3dfebc23e2a'; | ||
@@ -131,3 +145,3 @@ it('should successfully validate a v5 UUID', function() { | ||
it('should fail to validate an v5 UUID when the UUID is v1', function() { | ||
const v1 = '6000ad5c-5f8e-13f6-ba09-fba7e844a674'; | ||
var v1 = '6000ad5c-5f8e-13f6-ba09-fba7e844a674'; | ||
try { | ||
@@ -134,0 +148,0 @@ expect(v1).to.be.a.uuid('v5'); |
9103
174