-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: graceful handling of missing
source
prop
Also, the user will receive messages in dev mode about outdated props such as `html` and `uri`.
- Loading branch information
Showing
6 changed files
with
100 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
testRegex: 'src/.*(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', | ||
coveragePathIgnorePatterns: ['/node_modules/', '__tests__'] | ||
coveragePathIgnorePatterns: ['/node_modules/', '__tests__'], | ||
globals: { | ||
__DEV__: true | ||
} | ||
}; |
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
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
43 changes: 43 additions & 0 deletions
43
packages/render-html/src/__tests__/component.render-html-dev.test.tsx
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,43 @@ | ||
import React from 'react'; | ||
import { render } from 'react-native-testing-library'; | ||
import { RenderHTMLDev, messages } from '../RenderHTMLDebug'; | ||
|
||
describe('RenderHTMLDev', () => { | ||
it('should warn when contentWidth has not been provided', () => { | ||
console.warn = jest.fn(); | ||
render( | ||
<RenderHTMLDev source={{ html: '<p>Hello world</p>' }} debug={false} /> | ||
); | ||
expect(console.warn).toHaveBeenNthCalledWith(1, messages.contentWidth); | ||
}); | ||
it('should warn when source has not been provided', () => { | ||
console.warn = jest.fn(); | ||
//@ts-expect-error | ||
render(<RenderHTMLDev debug={false} />); | ||
expect(console.warn).toHaveBeenNthCalledWith(1, messages.noSource); | ||
}); | ||
it('should warn when outdated html prop has been provided', () => { | ||
console.warn = jest.fn(); | ||
render( | ||
React.createElement(RenderHTMLDev, { | ||
source: { html: 'hello world' }, | ||
//@ts-expect-error | ||
html: 'hello world', | ||
debug: false | ||
}) | ||
); | ||
expect(console.warn).toHaveBeenNthCalledWith(1, messages.outdatedHtmlProp); | ||
}); | ||
it('should warn when outdated uri prop has been provided', () => { | ||
console.warn = jest.fn(); | ||
render( | ||
React.createElement(RenderHTMLDev, { | ||
source: { html: 'hello world' }, | ||
//@ts-expect-error | ||
uri: 'https://foo.bar/', | ||
debug: false | ||
}) | ||
); | ||
expect(console.warn).toHaveBeenNthCalledWith(1, messages.outdatedUriProp); | ||
}); | ||
}); |
18 changes: 14 additions & 4 deletions
18
...tml/src/__tests__/component.html.test.tsx → .../__tests__/component.render-html.test.tsx
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