RegeneratorRuntime is not defined

后端 未结 5 533
渐次进展
渐次进展 2020-12-14 15:10

I am trying to run Karma-babel-preprocessor and a straight forward ES6 generator:

//require(\'babel/polyfill\');

  describe(\"how Generators work\", functio         


        
5条回答
  •  天涯浪人
    2020-12-14 15:31

    I modified karma.conf.js to add browser-polyfill as mentioned in the Docs Link:

    files: [
                'node_modules/babel/browser-polyfill.js',
          'test-main.js',
          {pattern: 'tests/*.js', included: true}
        ],
    

    After this modification, the following unit test works in Karma:

      describe("how Generators work", function() {
        it("will allow generator functions", function() {
         /*function* numbers(){
           yield 1;
           yield 2;
           yield 3;
         };*///Simplified syntax does not work
    
          let numbers = {
            [Symbol.iterator]:function*(){
                yield 1;
                yield 2;
                yield 3;
              }
          }
    
          let sum = 0;
    
          for(let num of numbers){
            sum += num;
          }
    
          expect(sum).toBe(6);
        });
      });
    

提交回复
热议问题