S
S
sanex33392015-07-24 15:26:07
JavaScript
sanex3339, 2015-07-24 15:26:07

What is the correct way to export a module with multiple ES6 classes for testing?

Essence:
There is a type code

(() => {
   class A {
   }

   class B extends A {
   }

   class C extends A {
   }

   class D {
       static foo () {
       }
   }

   let var;

   if (D.foo()) {
       var = new B;    
   } else {
       var = new C;
   }
})();

The whole thing in one file is cut into an HTML page, there are no other files.
How can I correctly export classes so that in the test spec I can import each class for testing, without breaking the code I'm testing and leaving all classes within their scope?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sanex3339, 2015-07-24
@sanex3339

I decided to do this: in resources, instead of a closure (although I have already redone the closure to an ES6 block {...}), there are //start and //end, and all classes have export.
When building, for production, //start and //end are changed to { and }, respectively, by gulp-replace, and they also remove the export before the classes. For a task with tests, this file is copied to the src directory with tests and tests through karma, jasmine and phantomjs access it already there, all classes are exported normally, tests are run.

_
_ _, 2015-07-25
@AMar4enko

Or you can just use browserify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question