Files
atom/spec/url-handler-registry-spec.js
2017-09-18 17:33:51 -07:00

39 lines
1.2 KiB
JavaScript

/** @babel */
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)
registry.handleUrl("atom://yet-another-package/path")
expect(testPackageSpy).not.toHaveBeenCalled()
expect(otherPackageSpy).not.toHaveBeenCalled()
registry.handleUrl("atom://test-package/path")
expect(testPackageSpy).toHaveBeenCalledWith("atom://test-package/path")
expect(otherPackageSpy).not.toHaveBeenCalled()
registry.handleUrl("atom://other-package/path")
expect(otherPackageSpy).toHaveBeenCalledWith("atom://other-package/path")
})
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()
})
})
})