pulsar/spec/url-handler-registry-spec.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-19 03:33:51 +03:00
/** @babel */
2017-09-27 22:40:21 +03:00
import url from 'url'
2017-09-19 03:33:51 +03:00
import {it} from './async-spec-helpers'
import UrlHandlerRegistry from '../src/url-handler-registry'
describe('UrlHandlerRegistry', () => {
let registry = new UrlHandlerRegistry()
it('handles URLs on a per-host basis', () => {
const testPackageSpy = jasmine.createSpy()
const otherPackageSpy = jasmine.createSpy()
registry.registerHostHandler('test-package', testPackageSpy)
registry.registerHostHandler('other-package', otherPackageSpy)
2017-09-27 22:40:21 +03:00
registry.handleUrl('atom://yet-another-package/path')
2017-09-19 03:33:51 +03:00
expect(testPackageSpy).not.toHaveBeenCalled()
expect(otherPackageSpy).not.toHaveBeenCalled()
2017-09-27 22:40:21 +03:00
registry.handleUrl('atom://test-package/path')
expect(testPackageSpy).toHaveBeenCalledWith(url.parse('atom://test-package/path', true), 'atom://test-package/path')
2017-09-19 03:33:51 +03:00
expect(otherPackageSpy).not.toHaveBeenCalled()
2017-09-27 22:40:21 +03:00
registry.handleUrl('atom://other-package/path')
expect(otherPackageSpy).toHaveBeenCalledWith(url.parse('atom://other-package/path', true), 'atom://other-package/path')
2017-09-19 03:33:51 +03:00
})
it('refuses to handle bad URLs', () => {
[
'atom:package/path',
'atom:8080://package/path',
'user:pass@atom://package/path',
'smth://package/path'
].forEach(uri => {
expect(() => registry.handleUrl(uri)).toThrow()
})
})
})