角度 2 - 量角器测试:找不到名称'element'和'name'



Hye,

我创建了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为我创建了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
}

}

您将导入语句留空。

import {by, element} from 'protractor';

最新更新