Testing components with Font Awesome Icons ModuleHow do I test a private function or a class that has private methods, fields or inner classes?Unit Testing C CodeWhat is Unit test, Integration Test, Smoke test, Regression Test?Angular Component Unit Testing - Component within ComponentsIs it possible to mock custom Angular 2 Material SVG icons for unit tests?Angular 2 'component' is not a known elementHow to import/use lazy load module on another ng-moduleIs unit test required for each and every component in angular 4?Angular Font Awesome in a component library - FontAwesome: Could not find icon with iconName=times and prefix=fasCore module component and Shared module implementation in angular

What is the Leave No Trace way to dispose of coffee grounds?

Extracting data from Plot

Strange outlet behavior

Increase speed altering column on large table to NON NULL

Are the guests in Westworld forbidden to tell the hosts that they are robots?

Why is long-term living in Almost-Earth causing severe health problems?

Tikz-cd diagram arrow passing under a node - not crossing it

What would be the way to say "just saying" in German? (Not the literal translation)

Command of files and size

Does the Nuka-Cola bottler actually generate nuka cola?

Was Self-modifying-code possible just using BASIC?

The origin of the Russian proverb about two hares

As easy as Three, Two, One... How fast can you go from Five to Four?

That's not my X, its Y is too Z

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

Difference between prepositions in "...killed during/in the war"

Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?

Grep Match and extract

Should I put programming books I wrote a few years ago on my resume?

Why are MBA programs closing in the United States?

Housemarks (superimposed & combined letters, heraldry)

How far would a landing Airbus A380 go until it stops with no brakes?

Can there be absolute velocity?

How can one's career as a reviewer be ended?



Testing components with Font Awesome Icons Module


How do I test a private function or a class that has private methods, fields or inner classes?Unit Testing C CodeWhat is Unit test, Integration Test, Smoke test, Regression Test?Angular Component Unit Testing - Component within ComponentsIs it possible to mock custom Angular 2 Material SVG icons for unit tests?Angular 2 'component' is not a known elementHow to import/use lazy load module on another ng-moduleIs unit test required for each and every component in angular 4?Angular Font Awesome in a component library - FontAwesome: Could not find icon with iconName=times and prefix=fasCore module component and Shared module implementation in angular






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm currently working in an Angular 6 project where I have imported several of the new font-awesome 5 icons using the Fort-awesome module for angular.



As expected, by doing so now some of my Unit Tests (Karma + Jasmine) won't pass due to not being able to render the fa-icon selectors in my pages.



I understand that I could use a CUSTOM_ELEMENTS_SCHEMA in the TestBed for each component but I don't know if by doing so I may have other side effects that would make my unit tests less reliable (i.e. other sub-components may stop being tested).



Another option is to simply import the module in each of the required unit tests, and in each of those, also add the library.add() with the required icons. I do think, however, this could end up being tedious as there may be between 20 and 50 icons depending on the type of application.



I've also thought, but haven't tried yet, to add a stub module for the icons, so I simply "ignore" them. I think this could be reasonable, but not sure what the best practice would be in this case.



Below an excerpt of my imports in App.Module



import FontAwesomeModule from '@fortawesome/angular-fontawesome';
import library from '@fortawesome/fontawesome-svg-core';
import faLock, faHourglassHalf, faLockOpen from '@fortawesome/free-solid-svg-icons';


And in the constructor



export class AppModule 
constructor()
library.add(
faHourglassHalf, // Task in progress
faLockOpen, // Archive task
faLock
);




Full repo here: https://github.com/Narshe1412/Code-Institute-Interactive-Frontend-Project/tree/taskman



As I know this is not debate forum I would simply ask:



  • What are the side effects of using CUSTOM_ELEMENTS_SCHEMA in this use case and, if reliability is an issue when using this, which of the other two options would be preferable?









share|improve this question



















  • 1





    Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

    – JB Nizet
    Mar 25 at 17:07

















0















I'm currently working in an Angular 6 project where I have imported several of the new font-awesome 5 icons using the Fort-awesome module for angular.



As expected, by doing so now some of my Unit Tests (Karma + Jasmine) won't pass due to not being able to render the fa-icon selectors in my pages.



I understand that I could use a CUSTOM_ELEMENTS_SCHEMA in the TestBed for each component but I don't know if by doing so I may have other side effects that would make my unit tests less reliable (i.e. other sub-components may stop being tested).



Another option is to simply import the module in each of the required unit tests, and in each of those, also add the library.add() with the required icons. I do think, however, this could end up being tedious as there may be between 20 and 50 icons depending on the type of application.



I've also thought, but haven't tried yet, to add a stub module for the icons, so I simply "ignore" them. I think this could be reasonable, but not sure what the best practice would be in this case.



Below an excerpt of my imports in App.Module



import FontAwesomeModule from '@fortawesome/angular-fontawesome';
import library from '@fortawesome/fontawesome-svg-core';
import faLock, faHourglassHalf, faLockOpen from '@fortawesome/free-solid-svg-icons';


And in the constructor



export class AppModule 
constructor()
library.add(
faHourglassHalf, // Task in progress
faLockOpen, // Archive task
faLock
);




Full repo here: https://github.com/Narshe1412/Code-Institute-Interactive-Frontend-Project/tree/taskman



As I know this is not debate forum I would simply ask:



  • What are the side effects of using CUSTOM_ELEMENTS_SCHEMA in this use case and, if reliability is an issue when using this, which of the other two options would be preferable?









share|improve this question



















  • 1





    Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

    – JB Nizet
    Mar 25 at 17:07













0












0








0








I'm currently working in an Angular 6 project where I have imported several of the new font-awesome 5 icons using the Fort-awesome module for angular.



As expected, by doing so now some of my Unit Tests (Karma + Jasmine) won't pass due to not being able to render the fa-icon selectors in my pages.



I understand that I could use a CUSTOM_ELEMENTS_SCHEMA in the TestBed for each component but I don't know if by doing so I may have other side effects that would make my unit tests less reliable (i.e. other sub-components may stop being tested).



Another option is to simply import the module in each of the required unit tests, and in each of those, also add the library.add() with the required icons. I do think, however, this could end up being tedious as there may be between 20 and 50 icons depending on the type of application.



I've also thought, but haven't tried yet, to add a stub module for the icons, so I simply "ignore" them. I think this could be reasonable, but not sure what the best practice would be in this case.



Below an excerpt of my imports in App.Module



import FontAwesomeModule from '@fortawesome/angular-fontawesome';
import library from '@fortawesome/fontawesome-svg-core';
import faLock, faHourglassHalf, faLockOpen from '@fortawesome/free-solid-svg-icons';


And in the constructor



export class AppModule 
constructor()
library.add(
faHourglassHalf, // Task in progress
faLockOpen, // Archive task
faLock
);




Full repo here: https://github.com/Narshe1412/Code-Institute-Interactive-Frontend-Project/tree/taskman



As I know this is not debate forum I would simply ask:



  • What are the side effects of using CUSTOM_ELEMENTS_SCHEMA in this use case and, if reliability is an issue when using this, which of the other two options would be preferable?









share|improve this question
















I'm currently working in an Angular 6 project where I have imported several of the new font-awesome 5 icons using the Fort-awesome module for angular.



As expected, by doing so now some of my Unit Tests (Karma + Jasmine) won't pass due to not being able to render the fa-icon selectors in my pages.



I understand that I could use a CUSTOM_ELEMENTS_SCHEMA in the TestBed for each component but I don't know if by doing so I may have other side effects that would make my unit tests less reliable (i.e. other sub-components may stop being tested).



Another option is to simply import the module in each of the required unit tests, and in each of those, also add the library.add() with the required icons. I do think, however, this could end up being tedious as there may be between 20 and 50 icons depending on the type of application.



I've also thought, but haven't tried yet, to add a stub module for the icons, so I simply "ignore" them. I think this could be reasonable, but not sure what the best practice would be in this case.



Below an excerpt of my imports in App.Module



import FontAwesomeModule from '@fortawesome/angular-fontawesome';
import library from '@fortawesome/fontawesome-svg-core';
import faLock, faHourglassHalf, faLockOpen from '@fortawesome/free-solid-svg-icons';


And in the constructor



export class AppModule 
constructor()
library.add(
faHourglassHalf, // Task in progress
faLockOpen, // Archive task
faLock
);




Full repo here: https://github.com/Narshe1412/Code-Institute-Interactive-Frontend-Project/tree/taskman



As I know this is not debate forum I would simply ask:



  • What are the side effects of using CUSTOM_ELEMENTS_SCHEMA in this use case and, if reliability is an issue when using this, which of the other two options would be preferable?






angular unit-testing karma-jasmine






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 16:57







Narshe

















asked Mar 24 at 21:39









NarsheNarshe

5611




5611







  • 1





    Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

    – JB Nizet
    Mar 25 at 17:07












  • 1





    Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

    – JB Nizet
    Mar 25 at 17:07







1




1





Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

– JB Nizet
Mar 25 at 17:07





Given that you're using the library, and that using an icon not added to (or accidentally removed from) the library could make your component fail, I would definitely not use CUSTOM_ELEMENTS_SCHEMA. I would simply import a module importing the FontAwesomeModule and adding the icons to the library, both in the test, and in the AppModule.

– JB Nizet
Mar 25 at 17:07












1 Answer
1






active

oldest

votes


















1














I would just like to throw out a 'third' option. This is the approach that my team and I have been using and prefer.



The module brings in the FontAwesomeModule.



import NgModule from '@angular/core';
import FontAwesomeModule from '@fortawesome/angular-fontawesome';

@NgModule(
declarations: [
AppComponent
],
imports: [
FontAwesomeModule
],
exports: [
FontAwesomeModule
]
)

export class AppModule


The component that actually uses the font awesome icons imports only the icons it needs to know about.



import 
Component
from '@angular/core';

import faLock from '@fortawesome/free-solid-svg-icons';

@Component(
selector: 'app-fa-example',
template: '<fa-icon [icon]="faLock"></fa-icon>'
)
export class AppComponent
faLock = faLock;



Then in our *.spec.ts files, we have a setup like the following:



TestBed.configureTestingModule(
imports: [
AppModule
]
)
.compileComponents();


Since the FontAwesomeModule is exported in the AppModule it will be available to the test bed here through the AppModule import. Since the icons are being imported explicitly in the component, there is no need to library.add(...) here either specifying all of the font awesome icons used in the module/component.






share|improve this answer























  • Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

    – Narshe
    Mar 25 at 22:24











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328832%2ftesting-components-with-font-awesome-icons-module%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I would just like to throw out a 'third' option. This is the approach that my team and I have been using and prefer.



The module brings in the FontAwesomeModule.



import NgModule from '@angular/core';
import FontAwesomeModule from '@fortawesome/angular-fontawesome';

@NgModule(
declarations: [
AppComponent
],
imports: [
FontAwesomeModule
],
exports: [
FontAwesomeModule
]
)

export class AppModule


The component that actually uses the font awesome icons imports only the icons it needs to know about.



import 
Component
from '@angular/core';

import faLock from '@fortawesome/free-solid-svg-icons';

@Component(
selector: 'app-fa-example',
template: '<fa-icon [icon]="faLock"></fa-icon>'
)
export class AppComponent
faLock = faLock;



Then in our *.spec.ts files, we have a setup like the following:



TestBed.configureTestingModule(
imports: [
AppModule
]
)
.compileComponents();


Since the FontAwesomeModule is exported in the AppModule it will be available to the test bed here through the AppModule import. Since the icons are being imported explicitly in the component, there is no need to library.add(...) here either specifying all of the font awesome icons used in the module/component.






share|improve this answer























  • Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

    – Narshe
    Mar 25 at 22:24















1














I would just like to throw out a 'third' option. This is the approach that my team and I have been using and prefer.



The module brings in the FontAwesomeModule.



import NgModule from '@angular/core';
import FontAwesomeModule from '@fortawesome/angular-fontawesome';

@NgModule(
declarations: [
AppComponent
],
imports: [
FontAwesomeModule
],
exports: [
FontAwesomeModule
]
)

export class AppModule


The component that actually uses the font awesome icons imports only the icons it needs to know about.



import 
Component
from '@angular/core';

import faLock from '@fortawesome/free-solid-svg-icons';

@Component(
selector: 'app-fa-example',
template: '<fa-icon [icon]="faLock"></fa-icon>'
)
export class AppComponent
faLock = faLock;



Then in our *.spec.ts files, we have a setup like the following:



TestBed.configureTestingModule(
imports: [
AppModule
]
)
.compileComponents();


Since the FontAwesomeModule is exported in the AppModule it will be available to the test bed here through the AppModule import. Since the icons are being imported explicitly in the component, there is no need to library.add(...) here either specifying all of the font awesome icons used in the module/component.






share|improve this answer























  • Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

    – Narshe
    Mar 25 at 22:24













1












1








1







I would just like to throw out a 'third' option. This is the approach that my team and I have been using and prefer.



The module brings in the FontAwesomeModule.



import NgModule from '@angular/core';
import FontAwesomeModule from '@fortawesome/angular-fontawesome';

@NgModule(
declarations: [
AppComponent
],
imports: [
FontAwesomeModule
],
exports: [
FontAwesomeModule
]
)

export class AppModule


The component that actually uses the font awesome icons imports only the icons it needs to know about.



import 
Component
from '@angular/core';

import faLock from '@fortawesome/free-solid-svg-icons';

@Component(
selector: 'app-fa-example',
template: '<fa-icon [icon]="faLock"></fa-icon>'
)
export class AppComponent
faLock = faLock;



Then in our *.spec.ts files, we have a setup like the following:



TestBed.configureTestingModule(
imports: [
AppModule
]
)
.compileComponents();


Since the FontAwesomeModule is exported in the AppModule it will be available to the test bed here through the AppModule import. Since the icons are being imported explicitly in the component, there is no need to library.add(...) here either specifying all of the font awesome icons used in the module/component.






share|improve this answer













I would just like to throw out a 'third' option. This is the approach that my team and I have been using and prefer.



The module brings in the FontAwesomeModule.



import NgModule from '@angular/core';
import FontAwesomeModule from '@fortawesome/angular-fontawesome';

@NgModule(
declarations: [
AppComponent
],
imports: [
FontAwesomeModule
],
exports: [
FontAwesomeModule
]
)

export class AppModule


The component that actually uses the font awesome icons imports only the icons it needs to know about.



import 
Component
from '@angular/core';

import faLock from '@fortawesome/free-solid-svg-icons';

@Component(
selector: 'app-fa-example',
template: '<fa-icon [icon]="faLock"></fa-icon>'
)
export class AppComponent
faLock = faLock;



Then in our *.spec.ts files, we have a setup like the following:



TestBed.configureTestingModule(
imports: [
AppModule
]
)
.compileComponents();


Since the FontAwesomeModule is exported in the AppModule it will be available to the test bed here through the AppModule import. Since the icons are being imported explicitly in the component, there is no need to library.add(...) here either specifying all of the font awesome icons used in the module/component.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 17:41









peinearydevelopmentpeinearydevelopment

5,13842549




5,13842549












  • Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

    – Narshe
    Mar 25 at 22:24

















  • Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

    – Narshe
    Mar 25 at 22:24
















Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

– Narshe
Mar 25 at 22:24





Thanks for your input. I will try this approach and see if it works with the rest of my codebase. In fact it may help start unit testing a bigger project I have at work where we've been neglecting automated tests for a while.

– Narshe
Mar 25 at 22:24



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328832%2ftesting-components-with-font-awesome-icons-module%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해