summaryrefslogtreecommitdiffhomepage
path: root/test/enum.spec.js
blob: dec15b219c3a738bb397251a9df72228e823824e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { expect } from 'chai';
import Enum from '../app/lib/enum';

describe('enum', () => {
  it('should be able to compare values', () => {
    const e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST');
    expect(e.NORTH).to.be.equal('NORTH');
  });

  it('should not be able to modify enum', () => {
    let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST');
    expect(() => e.ANYWHERE = 'ANYWHERE').to.throw();
  });

  it('should be able to validate enum keys', () => {
    let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST');
    expect(e.isValid('SOUTH')).to.be.true;
    expect(e.isValid('ANYWHERE')).to.be.false;
    expect(e.isValid()).to.be.false;
    expect(e.isValid(null)).to.be.false;
  });
});