我在网上搜索了很多答案并没有找到任何答案.
有没有办法通过Javascript获取浏览器的下载路径?
我不想自己设置路径,我只想知道用户下载文件后的位置.
我有一个文本输入,我正在听取更改.
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
我有一个非常松散的正则表达式来匹配字符串中的任何类型的 url:[a-z]+[:.].*?(?=\s|$)
唯一的问题是这个正则表达式也将匹配电子邮件的域,而我想从匹配中排除任何电子邮件地址。
准确地说,我确实想要以下匹配项(匹配的字符串以粗体显示)
测试example.com测试
测试 emailstring@myemail.com
我尝试过的任何解决方案都只是排除emailstring和匹配myemail.com
这是一个更完整的测试用例https://regex101.com/r/NsxzCM/3/
angular ×1
browser ×1
download ×1
email ×1
javascript ×1
path ×1
regex ×1
unit-testing ×1
url ×1