小编011*_*010的帖子

Jasmine SpyOn不止一次使用同样的方法

我有一个角度控制器,其方法可以调用$location.search()两次.

第一次只是$location.search()返回值.
第二次是$location.search("foo", null)清除它.

我的单元测试中有以下间谍:
spyOn($location, "search").and.returnValue({ foo: "bar" });

{foo:"bar"}即使我的实施确实如此,间谍似乎也会回来$location.search("foo", null).

我需要一种方法,根据参数为同一个方法设置两个不同的间谍.

我需要这个期望:
expect($location.search().foo).toEqual(null);
在单元测试结束时通过.

unit-testing jasmine angularjs

6
推荐指数
1
解决办法
4711
查看次数

量角器测试没有测试和断言输出,而只有规范

我正在尝试在量角器网站上进行教程https://angular.github.io/protractor/#/

但是,我的输出没有1 test, 3 assertions, 0 failures按预期包含。

相反,它是:

Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
.


1 spec, 0 failures
Finished in 12.273 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Run Code Online (Sandbox Code Playgroud)

配置文件:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js']
};
Run Code Online (Sandbox Code Playgroud)

测试文件:

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write …
Run Code Online (Sandbox Code Playgroud)

selenium node.js angularjs protractor

5
推荐指数
1
解决办法
4441
查看次数

如何使用PHP的DOMDocument获取元素的序列化HTML?

这是我的示例脚本:

$html = <<<HTML
<div class="main">
    <div class="text">
    Capture this text 1
    </div>
    <div class="date">
    May 2010
    </div>
</div>
<div class="main">
    <div class="text">
    Capture this text 2
    </div>
    <div class="date">
    June 2010
    </div>
</div>
HTML;

$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);


$tags = $xpath->query('//div[@class="main"]');
foreach ($tags as $tag) {
    print_r($tag->nodeValue."\n");
}
Run Code Online (Sandbox Code Playgroud)

这将是:

Capture this text 1 May 2010
Capture this text 2 June 2010 
Run Code Online (Sandbox Code Playgroud)

但我需要它输出:

<div class="text">
Capture this text 2
</div>
<div class="date">
June 2010
</div> …
Run Code Online (Sandbox Code Playgroud)

php dom domdocument

4
推荐指数
1
解决办法
2056
查看次数