小编Bol*_*lza的帖子

使用javascript获取浏览器下载路径

我在网上搜索了很多答案并没有找到任何答案.

有没有办法通过Javascript获取浏览器的下载路径?

我不想自己设置路径,我只想知道用户下载文件的位置.

javascript browser path download

12
推荐指数
2
解决办法
3万
查看次数

Angular2组件:测试表单输入值更改

我有一个文本输入,我正在听取更改.

mycomponent.ts

ngOnInit() {
    this.searchInput = new Control();
    this.searchInput.valueChanges
        .distinctUntilChanged()
        .subscribe(newValue => this.search(newValue))
}
search(query) {
    // do something to search
}
Run Code Online (Sandbox Code Playgroud)

mycomponent.html

<search-box>
    <input type="text" [ngFormControl]="searchInput" >
</search-box>
Run Code Online (Sandbox Code Playgroud)

运行应用程序一切正常,但我想对其进行单元测试.

所以这就是我的尝试

mycomponent.spec.ts

beforeEach(done => {
    createComponent().then(fix => {
        cmpFixture = fix
        mockResponse()
        instance = cmpFixture.componentInstance
        cmpFixture.detectChanges();
        done();
    })
})
describe('on searching on the list', () => {
        let compiled, input
        beforeEach(() => {
            cmpFixture.detectChanges();
            compiled = cmpFixture.debugElement.nativeElement;
            spyOn(instance, 'search').and.callThrough()
            input = compiled.querySelector('search-box > input')
            input.value = 'fake-search-query'
            cmpFixture.detectChanges();
        })
        it('should …
Run Code Online (Sandbox Code Playgroud)

unit-testing angular2-forms angular2-testing angular2-components angular

9
推荐指数
1
解决办法
9444
查看次数

正则表达式:匹配 url 但不匹配电子邮件域

我有一个非常松散的正则表达式来匹配字符串中的任何类型的 url:[a-z]+[:.].*?(?=\s|$) 唯一的问题是这个正则表达式也将匹配电子邮件的域,而我想从匹配中排除任何电子邮件地址。

准确地说,我确实想要以下匹配项(匹配的字符串以粗体显示)

测试example.com测试

测试 emailstring@myemail.com

我尝试过的任何解决方案都只是排除emailstring和匹配myemail.com

这是一个更完整的测试用例https://regex101.com/r/NsxzCM/3/

regex email url

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