Skip to content

Commit af95f15

Browse files
authored
Fix duotone tests (compat with newer rn-svg) (#61)
1 parent adb1186 commit af95f15

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: src/components/__tests__/FontAwesomeIcon.test.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ const faAcorn = {
4444
}
4545

4646

47+
// react-native-svg>9.x changed the way it uses the `fill` attribute. In earlier versions,
48+
// it used an array ([0, DECIMAL_COLOR]), whereas newer versions dropped the array
49+
// in favor of a scalar value %DECIMAL_COLOR%
50+
function getActualFillColorHex(element) {
51+
const fillProp = element.props.fill
52+
const decimalColor = Array.isArray(fillProp) ? fillProp[1] : fillProp;
53+
// convert to hex
54+
return decimalColor.toString(16);
55+
}
56+
4757
fontawesome.library.add(faCoffee, faCircle)
4858

4959
test.skip('renders with icon specified as array', () => {
@@ -237,7 +247,7 @@ describe('duotone support', () => {
237247
const tree = renderer.create(<FontAwesomeIcon icon={ faAcorn } style={ styles.icon }/>).toJSON()
238248
const primaryLayer = tree.children[0].children[0].children[1]
239249
const secondaryLayer = tree.children[0].children[0].children[0]
240-
expect(primaryLayer.props.fill[1].toString(16)).toEqual('ff0000ff')
250+
expect(getActualFillColorHex(primaryLayer)).toEqual('ff0000ff')
241251
expect(secondaryLayer.props.fillOpacity).toEqual(0.4)
242252
})
243253
})
@@ -251,7 +261,7 @@ describe('duotone support', () => {
251261
const tree = renderer.create(<FontAwesomeIcon icon={ faAcorn } style={ styles.icon } secondaryOpacity={ 0.123 } />).toJSON()
252262
const primaryLayer = tree.children[0].children[0].children[1]
253263
const secondaryLayer = tree.children[0].children[0].children[0]
254-
expect(primaryLayer.props.fill[1].toString(16)).toEqual('ff0000ff')
264+
expect(getActualFillColorHex(primaryLayer)).toEqual('ff0000ff')
255265
expect(secondaryLayer.props.fillOpacity).toEqual(0.123)
256266
})
257267
})
@@ -264,7 +274,7 @@ describe('duotone support', () => {
264274
})
265275
const tree = renderer.create(<FontAwesomeIcon icon={ faAcorn } style={ styles.icon } secondaryColor={ "red" } />).toJSON()
266276
const secondaryLayer = tree.children[0].children[0].children[0]
267-
expect(secondaryLayer.props.fill[1].toString(16)).toEqual('ffff0000')
277+
expect(getActualFillColorHex(secondaryLayer)).toEqual('ffff0000')
268278
expect(secondaryLayer.props.fillOpacity).toEqual(1)
269279
})
270280
})
@@ -277,7 +287,7 @@ describe('duotone support', () => {
277287
})
278288
const tree = renderer.create(<FontAwesomeIcon icon={ faAcorn } style={ styles.icon } secondaryColor={ "red" } secondaryOpacity={ 0.123 } />).toJSON()
279289
const secondaryLayer = tree.children[0].children[0].children[0]
280-
expect(secondaryLayer.props.fill[1].toString(16)).toEqual('ffff0000')
290+
expect(getActualFillColorHex(secondaryLayer)).toEqual('ffff0000')
281291
expect(secondaryLayer.props.fillOpacity).toEqual(0.123)
282292
})
283293
})

0 commit comments

Comments
 (0)