all files / js/ Randrix.class.test.js

100% Statements 32/32
91.67% Branches 11/12
100% Functions 10/10
100% Lines 29/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61        28× 28× 28× 361× 361×         361×     28× 361×     28× 19× 19× 19×           180×   180× 180×     180× 153× 153×       153× 153× 153× 153×     153×              
import 'babel-polyfill';
import TestHelper from './helper/TestHelper.class';
import Randrix from './Randrix.class';
 
const data = TestHelper.data();
data.class.configs.forEach((config) => {
  describe(`Randrix Class ${config.name}: `, () => {
    let element = {};
    beforeEach(function() {
      element = document.createElement('div');
      element.setAttribute(
        (config.selector) ? config.selector : 'data-randrix',
        'true'
      );
 
      document.body.appendChild(element);
    });
 
    afterEach(function() {
      document.body.removeChild(element);
    });
 
    if (config.type === 'fail') {
      it('Randrix Throw Errors', () => {
        expect(function() {
          new Randrix(config.settings);
        }).toThrow(new Error(config.expect));
      });
    } else {
      it('Randrix is Object', () => {
        const randrix = new Randrix(config.settings);
        expect(typeof randrix).toBe('object');
      });
 
      data.methods.forEach((method) => {
        it(`randrix.${method.name} is function`, () => {
          // eslint-disable-next-line no-unused-vars
          const randrix = new Randrix(config.settings);
          expect(eval(`typeof randrix.${method.name}`)).toBe(method.type);
        });
 
        if (method.expect) {
          let value = TestHelper.escape(method.value);
          it(
            `randrix.${method.name}(${value}) return ${method.expect}`,
            () => {
            // eslint-disable-next-line no-unused-vars
            const randrix = new Randrix(config.settings);
            if (method.callBefore) eval(`randrix.${method.callBefore}()`);
            Eif (data.debug) TestHelper.debug(config, method, value);
            expect(
              eval(`typeof randrix.${method.name}(value)`)
            ).toBe(method.expect);
            if (method.callAfter) eval(`randrix.${method.callAfter}()`);
          });
        }
      });
    }
  });
});