all files / js/ Randext.test.js

97.3% Statements 36/37
94.44% Branches 17/18
100% Functions 10/10
100% Lines 33/33
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 62 63 64 65 66 67 68 69 70 71 72 73 74        18× 18× 18× 277× 277×         277×     277×   277×           277× 275×       18× 277×     18× 11× 11× 11×           140×   140× 140×     140× 119× 119×       119× 119× 119× 119×     119×              
import 'babel-polyfill';
import TestHelper from './helper/TestHelper.class';
import Randext from './Randext.class';
 
const data = TestHelper.data();
data.class.configs.forEach((config) => {
  describe(`Randext Class ${config.name}: `, () => {
    let element = {};
    beforeEach(() => {
      element = document.createElement('div');
      element.setAttribute(
        (config.selector) ? config.selector : 'data-randext',
        'false'
      );
 
      const text = document.createTextNode(
        'Random letter animation effect to display text messages.'
      );
      element.appendChild(text);
 
      document.body.appendChild(element);
 
      // add the element to the configuration object
      // of each instance
      // because we do not like to create it every time with in test data
      // TODO: exeption to test no element is given
      if (config.settings && typeof config.settings === 'object') {
        if (!config.settings.element) config.settings.element = element;
      }
    });
 
    afterEach(() => {
      document.body.removeChild(element);
    });
 
    if (config.type === 'fail') {
      it('Randext Throw Errors', () => {
        expect(() => {
          new Randext(config.settings);
        }).toThrow(new Error(config.expect));
      });
    } else {
      it('Randext is Object', () => {
        const randext = new Randext(config.settings);
        expect(typeof randext).toBe('object');
      });
 
      data.methods.forEach((method) => {
        it(`randext.${method.name} is function`, () => {
          // eslint-disable-next-line no-unused-vars
          const randext = new Randext(config.settings);
          expect(eval(`typeof randext.${method.name}`)).toBe(method.type);
        });
 
        if (method.expect) {
          let value = TestHelper.escape(method.value);
          it(
            `randext.${method.name}(${value}) return ${method.expect}`,
            () => {
              // eslint-disable-next-line no-unused-vars
              const randext = new Randext(config.settings);
              if (method.callBefore) eval(`randext.${method.callBefore}()`);
              Iif (data.debug) TestHelper.debug(config, method, value);
              expect(
                eval(`typeof randext.${method.name}(value)`)
              ).toBe(method.expect);
              if (method.callAfter) eval(`randext.${method.callAfter}()`);
            });
        }
      });
    }
  });
});