2017-07-24 146 views
0

惠,角2 - 量角器测试:找不到名称 '元素' 和 '名'

我创建app.e2e-spec.ts文件创建单元测试:

import {} from 'jasmine'; 
import {} from 'protractor'; 

describe('Testing login button disable if empty input texts', function() { 
    it('should username have null value', function() { 
    var inputsLogin = element(by.name('username')); 
    expect<any>(inputsLogin.getAttribute('value')).toBe(null); 
    }); 

    it('should password have null value', function() { 
    var inputsPassword = element(by.name('password')); 
    expect<any>(inputsPassword.getAttribute('value')).toBe(null); 
    }); 

    it('should login button disable', function() { 
    var loginButton = element(by.id('button-confirm')); 
    expect<any>(loginButton.getAttribute('disabled')).toBe("true"); 
    }); 
}); 

的单元测试工作,但问题是,当我运行tsc命令,我得到这些错误:

tests/tests-e2e/app.e2e-specs.ts(10,27): error TS2304: Cannot find name 'element'. 
tests/tests-e2e/app.e2e-specs.ts(10,35): error TS2304: Cannot find name'by' 
tests/tests-e2e/app.e2e-specs.ts(15,30): error TS2304: Cannot find name'element' 
... 

但由于Intellj我

012创建JS有时候我可以运行我的测试个

我tsconfig.js:

{ 
"compilerOptions": { 
    "allowSyntheticDefaultImports": true, 
    "declaration": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": [ 
    "dom", 
    "es2015" 
    ], 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "target": "es5", 
    "typeRoots": [ 
    "./node_modules/@types/" 
    ] 
}, 
"include": [ 
    "src/**/*.ts", 
    "tests/**/*.ts" 
    ], 
"exclude": [ 
    "node_modules" 
], 
"compileOnSave": false, 
"atom": { 
"rewriteTsconfig": false 
} 

}

回答

2

你忘了你import语句空。

import {by, element} from 'protractor'; 
+0

谢谢我很笨我以为让导入语句空导入整个模块,但它是*。那么为什么它适用于茉莉花? – gigeos

+0

可能在您的配置中,茉莉花正在使用类型。类型不需要导入。 –