我正在尝试使用ng-apimock量角器插件在茉莉花上运行我的e2e测试。我正在尝试模拟的实际数据api在端口8000上运行。而我的angular应用程序在端口4200上运行。
遵循自述文件https://github.com/ng-apimock/protractor-plugin,https://github.com/ng-apimock/core和迁移步骤https://github.com/mdasberg/ng-apimock的解释:
package.json具有devDependencies:
...
"@ng-apimock/core": "^1.0.21",
"@ng-apimock/protractor-plugin": "^1.0.14"
...
我已经运行了npm install。
我的量角器配置(protractor.conf.js)文件如下:
...
exports.config = {
...
plugins: [{package: '@ng-apimock/protractor-plugin'}],
framework: 'jasmine',
baseUrl: 'http://localhost:4200/'
...
};
我的规格文件(sign-in.e2e-spec.ts)如下:
import {Client} from '@ng-apimock/base-client';
declare const ngApimock: Client;
...
describe('login', () => {
...
it('displays an error message if the signIn fails', async () => {
await ngApimock.selectScenario('login', 'wrong-credentials');
...
});
...
});
我的模拟文件login.mock.json:
{
"name": "login",
"isArray": true,
"request": {
"url": "/login",
"method": "POST",
"body": {
"username": "^[a-zA-Z]{3,10}$",
"password": "^[a-zA-Z]{3,10}$"
}
},
"responses": {
"ok": {
"status": 200,
"default": true
},
"wrong-credentials": {
"default": false,
"status": 400
}
}
}
我遇到以下错误:
Failed: An error occured while invoking http://localhost:4200/ngapimock/mocks that resulted in status code 404
我认为,我必须在某个时候指定端口8000,但找不到位置。我不确定插件配置是否正确。