javascript 这里的 `it()` 函数是做什么的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28353232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the `it()` function here doing?
提问by George
The following snippet of code is from angular's documentation. What is the it()
function here doing (I'm assuming it has some conventional meaning because otherwise no context seems to be given for its meaning)? I don't see any reference to it on angular's site. It's also hard to google due to it's name. The context is with regards to code testing.
以下代码片段来自angular 的文档。it()
这里的函数是做什么的(我假设它具有一些传统含义,否则似乎没有给出其含义的上下文)?我在 angular 的网站上没有看到任何对它的引用。由于它的名字,谷歌也很难。上下文与代码测试有关。
it('should say hello', function() {
var scopeMock = {};
var cntl = new MyController(scopeMock);
// Assert that username is pre-filled
expect(scopeMock.username).toEqual('World');
// Assert that we read new username and greet
scopeMock.username = 'angular';
scopeMock.sayHello();
expect(scopeMock.greeting).toEqual('Hello angular!');
});
回答by Aaron Greenwald
The it()
function is defined by the jasmine testing framework, it is not part of angular per se. You'll see it in angular's documentation because they are encouraging you (for good reason) to get in the habit of writing tests for your code, and demonstrating how the code will work in a test.
该it()
函数由 jasmine 测试框架定义,它本身不是 angular 的一部分。您会在 angular 的文档中看到它,因为它们鼓励您(有充分的理由)养成为代码编写测试的习惯,并演示代码在测试中的工作方式。
The it()
function defines a jasmine test. It is so named because its name makes reading tests almost like reading English. The second argument to the it()
function is itself a function, that when executed will probably run some number of expect()
functions. expect()
functions are used to actually test the things you "expect" to be true.
该it()
函数定义了一个茉莉花测试。它如此命名是因为它的名字使阅读测试几乎就像阅读英语一样。it()
函数的第二个参数本身就是一个函数,执行时可能会运行一些expect()
函数。expect()
函数用于实际测试您“期望”为真的事情。
Read more about jasmine testing on the jasmine framework's website: http://jasmine.github.io/
在 jasmine 框架的网站上阅读有关 jasmine 测试的更多信息:http: //jasmine.github.io/
回答by vlio20
it is related to tests with jasmine framework, you can find more information here:
http://jasmine.github.io/
https://docs.angularjs.org/guide/unit-testing
它与使用 jasmine 框架的测试有关,您可以在此处找到更多信息:http:
//jasmine.github.io/
https://docs.angularjs.org/guide/unit-testing