-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for exotic component fixes #82
- Loading branch information
1 parent
1111666
commit 6dc0fb0
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as React from 'react'; | ||
import { convertComponent } from './components'; | ||
import { ComponentConverters, HtmlComponent } from '../types'; | ||
|
||
describe('Component Converters Module', () => { | ||
it('React FC is correctly marked', () => { | ||
const Component = () => <div />; | ||
const converters: ComponentConverters<any> = { | ||
html() { | ||
return undefined; | ||
}, | ||
}; | ||
const result = convertComponent(converters, Component, 'test'); | ||
expect(result).toHaveProperty('displayName', 'test'); | ||
expect(result).not.toHaveProperty('converted'); | ||
}); | ||
|
||
it('React class component is correctly marked', () => { | ||
const Component = class extends React.Component { | ||
render() { | ||
return <div />; | ||
} | ||
}; | ||
const converters: ComponentConverters<any> = { | ||
html() { | ||
return undefined; | ||
}, | ||
}; | ||
const result = convertComponent(converters, Component, 'test'); | ||
expect(result).toHaveProperty('displayName', 'test'); | ||
expect(result).not.toHaveProperty('converted'); | ||
}); | ||
|
||
it('React exotic component is correctly marked', () => { | ||
const Component = React.lazy(() => | ||
Promise.resolve().then(() => ({ | ||
default: () => <div />, | ||
})), | ||
); | ||
const converters: ComponentConverters<any> = { | ||
html() { | ||
return undefined; | ||
}, | ||
}; | ||
const result = convertComponent(converters, Component, 'test'); | ||
expect(result).toHaveProperty('displayName', 'test'); | ||
expect(result).not.toHaveProperty('converted'); | ||
}); | ||
|
||
it('HTML component is correctly marked', () => { | ||
const Component: HtmlComponent<any> = { | ||
type: 'html', | ||
render() { | ||
return undefined; | ||
}, | ||
}; | ||
const converters: ComponentConverters<any> = { | ||
html(): any { | ||
return { | ||
converted: true, | ||
}; | ||
}, | ||
}; | ||
const result = convertComponent(converters, Component, 'test'); | ||
expect(result).not.toHaveProperty('displayName'); | ||
expect(result).toHaveProperty('converted', true); | ||
}); | ||
|
||
it('Unknown component throws', () => { | ||
const Component = { | ||
type: 'foo', | ||
}; | ||
const converters: ComponentConverters<any> = { | ||
html() { | ||
return undefined; | ||
}, | ||
}; | ||
expect(() => convertComponent(converters, Component as any, 'test')).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters