Sha256: f883b2c11c53d2097c120c437844a644c49cf8b4ce36c3c801760ec19eff68e0

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

import { assign } from '@ember/polyfills';
import getAllPropertyNames from './get-all-property-names';

function isGenerator(mixin) {
  return Array.isArray(mixin.cases) && typeof mixin.generate === 'function';
}

export default function applyMixins(TestClass, ...mixins) {
  mixins.forEach(mixinOrGenerator => {
    let mixin;

    if (isGenerator(mixinOrGenerator)) {
      let generator = mixinOrGenerator;
      mixin = {};

      generator.cases.forEach((value, idx) => {
        assign(mixin, generator.generate(value, idx));
      });

      assign(TestClass.prototype, mixin);
    } else if (typeof mixinOrGenerator === 'function') {
      let properties = getAllPropertyNames(mixinOrGenerator);
      mixin = new mixinOrGenerator();

      properties.forEach(name => {
        TestClass.prototype[name] = function() {
          return mixin[name].apply(mixin, arguments);
        };
      });
    } else {
      mixin = mixinOrGenerator;
      assign(TestClass.prototype, mixin);
    }
  });

  return TestClass;
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/internal-test-helpers/lib/apply-mixins.js
discourse-ember-source-3.5.1.1 dist/es/internal-test-helpers/lib/apply-mixins.js
discourse-ember-source-3.5.1.0 dist/dist/es/internal-test-helpers/lib/apply-mixins.js