我正在尝试使用 TypScript 编写我的 Cucumber 测试,如下所示:
import { browser, $$ } from 'protractor';
import { Given, Then } from 'cucumber'
import { expect } from 'chai';
Given('I navigate to the homepage', function (callback) {
browser.get('http://localhost:4200');
callback();
});
Then('I want to see the welcome message {string}', function (message, callback) {
expect($$('h1').first().getText()).to.eventually.equal(message).and.notify(callback);
});
Run Code Online (Sandbox Code Playgroud)
然而,量角器抱怨:
错误:无效的柴属性:最终
我怎样才能导入这个?我试过了:
import { eventual } from 'chai-as-promised';
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我怎样才能做到这一点?我还尝试使用 重写Then
调用await
,但编译器抱怨您不能将回调与异步函数混合使用。啊!
const chaiAsPromised = require('chai-as-promised');
const chai = require('chai');
const expect = chai.expect;
chai.use(chaiAsPromised);
describe('[sample unit]', function() {
it('should pass functionToTest with true input', function() {
expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("meh");
});
});
Run Code Online (Sandbox Code Playgroud)
这个测试通过??? 我正在使用"chai":"3.5.0","chai-as-promised":"5.2.0",
我tyring测试使用的承诺与一些代码chai-as-promised
和Mocha
。我的测试套件还使用fetch-mock来模拟通常使用 Fetch API 发送的 AJAX 请求。
这是我要测试的代码:
/**
* Sends a POST request to save (either insert or update) the record
* @param {object} record simple object of column name to column value mappings
* @return {Promise} Resolves when the POST request full response has arrived.
* Rejects if the POST request's response contains an Authorization error.
*/
save(record) {
var _this = this;
return this._auth(record)
.then(function() {
return window.fetch(_this._getPostUrl(), {
method: 'post',
headers: …
Run Code Online (Sandbox Code Playgroud) 使用量角器时,mocha框架中承诺的chai和chai有什么区别?
我是java脚本量角器黄瓜框架的新手.
我可以在一年前看到类似的问题,但这也是在一年前的量角器版本中修复的.因此提出了一个新问题.
我正在使用最新版本的黄瓜,量角器,量角器 - 黄瓜 - 框架,柴,柴 - 承诺.我使用visual studio代码作为编辑器.节点版本是6.11.4.有关所有版本的详细信息,请查看下面的package.json.
当我执行我的测试时,它会在不到一秒的时间内完成传递结果,但它只是启动浏览器,然后在浏览器中不执行任何操作.
请查看我正在使用的文件,并告诉我问题出在哪里.我不确定这是否是最新版本的量角器中的总线.
protractor.conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['features/*.feature'],
getPageTimeout: 60000,
allScriptsTimeout: 500000,
baseURL: 'http://www.protractortest.org/testapp/ng1/#/form',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
cucumberOpts: {
require: [ './features/step_definitions/*.steps.js' ],
tags: false,
profile: false,
'no-source': true
}
};
Run Code Online (Sandbox Code Playgroud)
的package.json:
{
"name": "protractor_test",
"version": "1.0.0",
"description": "",
"main": "protractor.conf.js",
"dependencies": {
"protractor": "^5.2.0",
"cucumber": "^3.1.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"@types/chai-as-promised": "^7.1.0",
"@types/cucumber": "^2.0.4",
"@types/protractor": "^4.0.0"
},
"devDependencies": {
"protractor-cucumber-framework": "^4.1.1" …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Chai 进行测试,我想深入比较 promise 中返回的对象。
我试过这种方法:
expect(promise).to.eventually.eql(object)
expect(promise).deep.equals(object)
expect(promise).should.eventually.equal(object)
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我检查了许多其他样本,但没有一个有效。这就是我得到的:
断言错误:未指定的断言错误
有没有人经历过类似的事情?
(顺便说一句,“对象”包含一个对象数组......)
chai ×5
mocha.js ×4
javascript ×3
protractor ×3
angular ×1
cucumber ×1
cucumberjs ×1
testing ×1
unit-testing ×1