2017-02-28 3 views
2

테스트를 수행하기 위해 mocha에서 async/await를 사용하고 싶습니다. 많은 게시물을 읽었지만 솔루션을 찾지 못했습니다. 코드를 번역하기 위해 모든 바벨 모듈을 이미 설치했지만 작동하지 않습니다. 여기 mocha에서 async/await를 사용하려고 시도합니다.

import test from 'mocha' 
import 'babel-polyfill' 
import { expect } from 'chai' 
import { assert } from 'chai' 
import utils from '../lib/utils' 

describe('long number', function() { 
    it("Sample", mochaAsync(async() => { 
    var x = utils.longNums(0); 
    expect(x).to.equal(5000); 
    })) 
}) 

나는 내가 설치해야 읽은 모든 바벨 종속성 및 플러그인을 사용하고 내 package.json, 내 테스트입니다 : 여기

는 "테스트"폴더 안에 내 코드입니다 내가 제안 스크립트는

it('should remove items that don\'t evaluate to true when passed to predicate function', async function() { 
                          ^^^^^ 
SyntaxError: missing) after argument list 
을 따르고 내가 할

{ 
    "name": "pos_lisa-test", 
    "version": "1.0.0", 
    "description": "pos lisa test", 
    "main": "index.js", 
    "scripts": { 
     "test": "mocha --compilers js:babel-core/register ./src/**/*.test.js" 
    }, 
    "standard": { 
     "parser": "babel-eslint" 
    }, 
    "babel": { 
     "presets": [ 
     "es2015", 
     "react" 
     ] 
    }, 
    "keywords": [ 
     "test" 
    ], 
    "author": "Mauricio", 
    "license": "MIT", 
    "devDependencies": { 
     "babel-core": "^6.23.1", 
     "babel-eslint": "^7.1.1", 
     "babel-plugin-transform-async-to-generator": "^6.22.0", 
     "babel-preset-es2015": "^6.22.0", 
     "babel-preset-react": "^6.23.0", 
     "chai": "^3.5.0", 
     "mocha": "^3.2.0", 
    }, 
    "plugins": [ 
     "transform-async-to-generator" 
    ], 
    "dependencies": { 
     "babel-polyfill": "^6.23.0" 
    } 
    } 

을 transpiling 바벨 그리고 오류를 사용하는 모카하기

내가 뭘 잘못하고있는거야? 사전에 많은 도움을 주셔서 감사합니다.

+0

바벨 구성이란 무엇입니까? 그것은 당신이 그것을 설치했기 때문에 비동기 변환을 적용하지 않을 것입니다. – estus

답변

1

package.json의 최상위 레벨에 "plugins": ["transform-async-to-generator"]"을 추가했지만 "babel" 섹션 안에 있어야합니다. 로 변경 : 자바 스크립트의도 (道)에 따르면

"babel": { 
    "presets": [ 
    "es2015", 
    "react" 
    ], 
    "plugins": [ 
    "transform-async-to-generator" 
    ] 
}, 
0

". 코드는 순간에 흐름, 그래서 지식은 스트림의지도처럼,하지만 힌트"

2017 년 4 월 현재 'transform-async-to-generator'를 사용하면 실제로 문제가 발생합니다.

보다 일반적인 메모로서, 모든 async 함수는 약속을 반환하거나 반환 값과 예외를 약속으로 변환합니다. 약속을 시험하고 시험 전화를받지 않는 것이 일반적으로 더 좋습니다. await :

it('should have no drops left',() => 
    ocean.listDrops().should.eventually.have.length(0));