gpt4 book ai didi

javascript - 有人可以解释以下 Angular 测试代码中调用的 evaluate() 和 dragAndDrop() 是什么吗?

转载 作者:行者123 更新时间:2023-11-30 16:06:25 25 4
gpt4 key购买 nike

以下代码用于使用 Protractor 测试 angular-Gridster 应用程序的拖放方向。

我对下面的一些函数调用不熟悉,有人能解释一下 evaluate() 的意义吗——API 定义太困惑了,还有 dragAndDrop()? -- 在任何地方都找不到这个函数

describe('DragAndDrop Test', function () {

require('jasmine-expect');

beforeAll(function () {
context = new Context();
context.get();
browser.waitForAngular();
browser.driver.manage().window().maximize();

});

it('should drag and drop a tile', function () {

//target is where we are dragging the box to. Box is the Box
var target = { x: 400, y: 400 };
var box = element(by.css('.ng-scope.gridster-item'));

//scope is going to hold the scope variables that tell us where the box is located
//see the documentation for angular gridster on github for info on scope variable
//get the standardItems Scope
box.evaluate('standardItems').then(function (scope) {

//make sure the box we are using is in column 0 and Row 0
expect(scope[0].col).toEqual(0);
expect(scope[0].row).toEqual(0);
});

//drag and drop the box somewhere else.
browser.actions().dragAndDrop(box, target).perform();
browser.waitForAngular();

//get the updated scope
box.evaluate('standardItems').then(function (scope) {

//test to see that the box was actually moved to column and row 2, better test
expect(scope[0].col).toEqual(2);
expect(scope[0].row).toEqual(2);
});
//this is to test the pixel location which is not the best
box.getLocation().then(function (location) {
expect(location.x).toEqual(476);
});
});
});

var Context = function () {

//load the website
this.get = function () {
browser.get('https://rawgit.com/ManifestWebDesign/angular-gridster/master/index.html#/main');
};
};

最佳答案

evaluate()将在您调用它的元素的范围内评估表达式。当您需要访问范围内的特定变量时很有用:

Evaluates the input as if it were on the scope of the current element.


dragAndDrop()是一个“浏览器操作”,继承自 WebDriverJS(请记住, Protractor 构建在 WebDriverJS 之上):

Convenience function for performing a "drag and drop" manuever. The target element may be moved to the location of another element, or by an offset (in pixels).

关于javascript - 有人可以解释以下 Angular 测试代码中调用的 evaluate() 和 dragAndDrop() 是什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36973216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com