Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parse only if not an icon object #327

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
162 changes: 74 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -26,9 +26,8 @@
"scripts": {
"build": "rollup -c rollup.config.js",
"dist": "cross-env NODE_ENV=production npm run build",
"test": "npm run test.latest && npm run test.next",
"test": "npm run test.latest && npm run test.next.proregistry",
"test.latest": "npm --no-save install @fortawesome/fontawesome-svg-core@latest @fortawesome/free-solid-svg-icons@latest && jest --silent",
"test.next": "npm --no-save install @fortawesome/fontawesome-svg-core@next @fortawesome/free-solid-svg-icons@next && jest --silent",
"test.next.proregistry": "npm --userconfig .npmrc.proregistry --registry https://npm.fontawesome.com install --no-save @fortawesome/fontawesome-svg-core@next @fortawesome/free-solid-svg-icons@next && jest --silent",
"prepack": "npm run dist"
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/FontAwesomeIcon.js
Expand Up @@ -4,6 +4,12 @@ import log from '../logger'
import { objectWithKey, classList } from '../utils'

function normalizeIconArgs (icon) {
// this has everything that it needs to be rendered which means it was probably imported
// directly from an icon svg package
if (icon && typeof icon === 'object' && icon.prefix && icon.iconName && icon.icon) {
return icon
}

if (faParse.icon) {
return faParse.icon(icon)
}
Expand All @@ -12,7 +18,7 @@ function normalizeIconArgs (icon) {
return null
}

if (typeof icon === 'object' && icon.prefix && icon.iconName) {
if (icon && typeof icon === 'object' && icon.prefix && icon.iconName) {
return icon
}

Expand Down
15 changes: 13 additions & 2 deletions src/components/__tests__/FontAwesomeIcon.test.js
@@ -1,7 +1,7 @@
import Vue from 'vue/dist/vue'
import FontAwesomeIcon from '../FontAwesomeIcon'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faClose } from '@fortawesome/free-solid-svg-icons'
import { faClose, faUser } from '@fortawesome/free-solid-svg-icons'
import { faCoffee, faCircle, faSpartan } from '../__fixtures__/icons'
import { coreHasFeature, REFERENCE_ICON_USING_STRING, REFERENCE_ICON_BY_STYLE, ICON_ALIASES, compileAndMount, mountFromProps } from '../__fixtures__/helpers'

Expand All @@ -10,6 +10,10 @@ beforeEach(() => {
Vue.component('font-awesome-icon', FontAwesomeIcon)
})

afterEach(() => {
library.reset()
})

test('using a FAT icon with array format', () => {
const vm = mountFromProps({ icon: ['fat', 'spartan'] })

Expand All @@ -33,7 +37,7 @@ if(coreHasFeature(ICON_ALIASES)) {
const vm = mountFromProps({ icon: ['fas', 'close'] })

expect(vm.$el.tagName).toBe('svg')
expect(vm.$el.classList.contains('fa-close')).toBeTruthy()
expect(vm.$el.classList.contains('fa-xmark')).toBeTruthy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you want the fa-xmark icon here?
In v6 xmark is the name of the icon and close is the alias.
If we keep the fa-mark we will need to import it (line 4), and will probably want to change the test name; currently test is 'find a free-solid-svg-icon that is an alias'.
As of right now, the test mentioned on the previous line fails because xmark has NOT been imported.

})
}

Expand Down Expand Up @@ -69,6 +73,13 @@ if (coreHasFeature(REFERENCE_ICON_BY_STYLE)) {
})
}

test('passing icon directly', () => {
const vm = mountFromProps({ icon: faUser })

expect(vm.$el.tagName).toBe('svg')
expect(vm.$el.classList.contains('fa-user')).toBeTruthy()
})

test('using array format', () => {
const vm = mountFromProps({ icon: ['fas', 'coffee'] })

Expand Down