Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rfrench/chai-uuid
Chai plugin for performing assertions on UUIDs
https://github.com/rfrench/chai-uuid
assertions bdd chai guid javascript mocha tdd uuid
Last synced: 3 months ago
JSON representation
Chai plugin for performing assertions on UUIDs
- Host: GitHub
- URL: https://github.com/rfrench/chai-uuid
- Owner: rfrench
- License: mit
- Created: 2017-06-10T01:11:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-04T02:34:17.000Z (about 7 years ago)
- Last Synced: 2024-09-28T22:21:43.503Z (4 months ago)
- Topics: assertions, bdd, chai, guid, javascript, mocha, tdd, uuid
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chai-uuid
Chai plugin for performing assertions on UUIDs## Install
```bash
$ npm install chai-uuid
```## Example
Use the `uuid` or `guid` method to test whether the assertion is a valid UUID.```javascript
const chai = require("chai");
chai.use(require('chai-uuid'));
```## Expect
```javascript
const chai = require("chai");
chai.use(require('chai-uuid'));
const expect = chai.expect;// validate UUID v1
expect('bd74c8da-4d9e-11e7-b114-b2f933d5fe66').to.be.a.uuid('v1');
// validate UUID v2
expect('f6b93689-1c6a-2931-a785-c7d5606f7f4d').to.be.a.uuid('v2');
// validate UUID v3
expect('622ab4f8-c3e7-3747-a548-0e2d11bf5ab1').to.be.a.uuid('v3');
// validate UUID v4
expect('0ce529f4-8854-41ec-b67c-fbcb4e716e42').to.be.a.uuid('v4');
// validate UUID v5
expect('48a698a0-1641-5aca-bc1b-de9b1a482ee1').to.be.a.uuid('v5');
// validate UUID (any version)
expect('a416d989-91d1-48c9-b583-267df138834c').to.be.a.uuid();// optionally, you can use the guid method
expect('a416d989-91d1-48c9-b583-267df138834c').to.be.a.guid();
```## Should
```javascript
const chai = require("chai");
chai.use(require('chai-uuid'));
const should = chai.should();// validate UUID v1
'bd74c8da-4d9e-11e7-b114-b2f933d5fe66'.should.be.a.uuid('v1');// validate GUID
'bd74c8da-4d9e-11e7-b114-b2f933d5fe66'.should.be.a.guid();
```## Assert
```javascript
const chai = require("chai");
chai.use(require('chai-uuid'));
const assert = chai.assert;// validate UUID v1
assert.uuid('bd74c8da-4d9e-11e7-b114-b2f933d5fe66', 'v1');// validate GUID
assert.guid('bd74c8da-4d9e-11e7-b114-b2f933d5fe66');
```