“它"是什么意思?这段代码中的功能是什么? [英] What does the "it" function do in this code?

查看:18
本文介绍了“它"是什么意思?这段代码中的功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以向我解释它"在 AngularJS 或纯 JavaScript 中的作用(用于)什么(我不确定它是否特定于 Angular).事实证明,这对谷歌来说是一件困难的事情,被命名为它"等等.我已经看到它在整个 AngularJS 文档中使用.我会给你一个来自 ngShow 页面的例子(它是隐藏/显示包含大拇指或大拇指向下).

I'm hoping somebody could explain to me what "it" does (is used for) in AngularJS or just plain JavaScript (I'm not sure if it's specific to Angular). This, turns out, is a difficult thing to Google for, being named "it" and all. I've seen it used throughout the AngularJS docs. I'll give you an example from the ngShow page (it's code to hide/show a div containing a thumbs up or thumbs down).

var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));

it('should check ng-show / ng-hide', function() {
  expect(thumbsUp.isDisplayed()).toBeFalsy();
  expect(thumbsDown.isDisplayed()).toBeTruthy();

  element(by.model('checked')).click();

  expect(thumbsUp.isDisplayed()).toBeTruthy();
  expect(thumbsDown.isDisplayed()).toBeFalsy();
});

推荐答案

参见 Jasmine 测试框架.

it(...) 函数定义了一个测试用例(又名规范").

See the Jasmine testing framework.

The it(...) function defines a test case (aka a "spec").

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

请注意,AngularJS E2E 测试...

... 使用 Jasmine 作为其测试语法.

... uses Jasmine for its test syntax.

这篇关于“它"是什么意思?这段代码中的功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆