Selecting a specific TemplateRef from Angular component test?@Directive v/s @Component in AngularHow can I select an element in a component template?Angular - Use pipes in services and componentsBinding select element to object in AngularDynamic tabs with user-click chosen componentsAngular/RxJs When should I unsubscribe from `Subscription`Angular 2 + jQuery + Materialize - how to Test?Testing angular service subscribe/unsubscribe from within a componentAngular Unit Test Component Callthrough On SpyObject of ServiceHow to test data loading states in an angular component?
How do we know neutrons have no charge?
Garage door sticks on a bolt
What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?
Top off gas with old oil, is that bad?
Knights and Knaves: What does C say?
Why would an airline put 15 passengers at once on standby?
What in my code changed between MacTeX 2017 and MacTex 2019?
An impressive body of work
Equations with summation ("sum") symbols
Calculate the Ultraradical
Kinematic formula for Euler characteristic
Is population size a parameter, or sample size a statistic?
Sci-fi movie with one survivor and an organism(?) recreating his memories
Concerning a relationship in the team
Installation of ImageMagick software fails with "configure: error: libltdl is required"
Is there a relationship between prime numbers and music?
Mathematica code for bifurcation diagram in 3D
Is the order of words purely based on convention?
Can I exile my opponent's Progenitus/True-Name Nemesis with Teferi, Hero of Dominaria's emblem?
Population of post-Soviet states. Why decreasing?
Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?
Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?
Why isn't there armor to protect from spells in the Potterverse?
Where to find the Arxiv endorsement code?
Selecting a specific TemplateRef from Angular component test?
@Directive v/s @Component in AngularHow can I select an element in a component template?Angular - Use pipes in services and componentsBinding select element to object in AngularDynamic tabs with user-click chosen componentsAngular/RxJs When should I unsubscribe from `Subscription`Angular 2 + jQuery + Materialize - how to Test?Testing angular service subscribe/unsubscribe from within a componentAngular Unit Test Component Callthrough On SpyObject of ServiceHow to test data loading states in an angular component?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the following component that has links to open a modal, which I can vary the content of by passing a template reference into.
<a id="spec-tos" (click)="openModal($event, termsOfServiceModalTemplate)">Terms of Service</a>
<a id="spec-pp" (click)="openModal($event, privacyPolicyModalTemplate)">Privacy</a>
<ng-template #termsOfServiceModalTemplate>
terms of service text goes here...
</ng-template>
<ng-template #privacyPolicyModalTemplate>
privacy policy text goes here...
</ng-template>
export class FooterComponent BsModalRef;
constructor(private modalService: BsModalService)
openModal($event: Event, template: TemplateRef<NgTemplateOutlet>): void
$event.preventDefault();
this.modalRef = this.modalService.show(template,
class: 'modal-dialog-scrollable'
);
How can I test that the links open the correct template? I need to be able to select the templateRef ID from my test, but I'm not sure how to do this. here's my test
it('should call the openModal() method when clicking on the privacy policy link', () =>
spyOn(component, 'openModal');
const link = debugEl.query(By.css('#spec-pp'));
//This next line is wrong and does not work
const tmpl = debugEl.query(By.directive(TemplateRef));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledWith(new MouseEvent('click'), tmpl);
);
I know that debugEl.query(By.directive(TemplateRef))
does not work... but that's just to give an idea of what I want to do here. How do I select a specific template from the component I'm testing?
Edit: The answer from @neo below is the solution, but I was able to take his solution and package it up into a re-usable helper function
/**
* Used for detecting an `<ng-template>` element reference that was passed to a function, typically for modals
* We don't have access to much except the name of the template and a number that it maps to internally.
* If we can return the number, then we've found the template by name, which is all we really want to do here
* //https://stackoverflow.com/a/55432163/79677
*/
export const templateExists = (template: TemplateRef<NgTemplateOutlet>, templateName: string): boolean =>
// tslint:disable-next-line:no-any -- There is no other way to get this object, it doesn't exist in the typedefs!
const refs = (template as any)._def.references as [templateName: string]: number;
//If we have a number, then we've found the template by name
return !isNaN(refs[templateName]);
;
Use it like this:
it('should call the openModal() method when clicking on the privacy policy link', () =>
const modalSpy = spyOn(component, 'openModal');
const link = debugEl.query(By.css('.footer-nav .spec-privacy'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(templateExists(modalSpy.calls.mostRecent().args[1], 'privacyPolicyModalTemplate')).toEqual(true);
);
angular angular-template angular-test angular-testing
add a comment
|
I have the following component that has links to open a modal, which I can vary the content of by passing a template reference into.
<a id="spec-tos" (click)="openModal($event, termsOfServiceModalTemplate)">Terms of Service</a>
<a id="spec-pp" (click)="openModal($event, privacyPolicyModalTemplate)">Privacy</a>
<ng-template #termsOfServiceModalTemplate>
terms of service text goes here...
</ng-template>
<ng-template #privacyPolicyModalTemplate>
privacy policy text goes here...
</ng-template>
export class FooterComponent BsModalRef;
constructor(private modalService: BsModalService)
openModal($event: Event, template: TemplateRef<NgTemplateOutlet>): void
$event.preventDefault();
this.modalRef = this.modalService.show(template,
class: 'modal-dialog-scrollable'
);
How can I test that the links open the correct template? I need to be able to select the templateRef ID from my test, but I'm not sure how to do this. here's my test
it('should call the openModal() method when clicking on the privacy policy link', () =>
spyOn(component, 'openModal');
const link = debugEl.query(By.css('#spec-pp'));
//This next line is wrong and does not work
const tmpl = debugEl.query(By.directive(TemplateRef));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledWith(new MouseEvent('click'), tmpl);
);
I know that debugEl.query(By.directive(TemplateRef))
does not work... but that's just to give an idea of what I want to do here. How do I select a specific template from the component I'm testing?
Edit: The answer from @neo below is the solution, but I was able to take his solution and package it up into a re-usable helper function
/**
* Used for detecting an `<ng-template>` element reference that was passed to a function, typically for modals
* We don't have access to much except the name of the template and a number that it maps to internally.
* If we can return the number, then we've found the template by name, which is all we really want to do here
* //https://stackoverflow.com/a/55432163/79677
*/
export const templateExists = (template: TemplateRef<NgTemplateOutlet>, templateName: string): boolean =>
// tslint:disable-next-line:no-any -- There is no other way to get this object, it doesn't exist in the typedefs!
const refs = (template as any)._def.references as [templateName: string]: number;
//If we have a number, then we've found the template by name
return !isNaN(refs[templateName]);
;
Use it like this:
it('should call the openModal() method when clicking on the privacy policy link', () =>
const modalSpy = spyOn(component, 'openModal');
const link = debugEl.query(By.css('.footer-nav .spec-privacy'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(templateExists(modalSpy.calls.mostRecent().args[1], 'privacyPolicyModalTemplate')).toEqual(true);
);
angular angular-template angular-test angular-testing
Can you provide theBsModalRef
andBsModalService
classes, I think I may able to help you.
– Anuradha Mudalige
Mar 28 at 19:43
those are fromngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them
– CBarr
Mar 28 at 21:22
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14
add a comment
|
I have the following component that has links to open a modal, which I can vary the content of by passing a template reference into.
<a id="spec-tos" (click)="openModal($event, termsOfServiceModalTemplate)">Terms of Service</a>
<a id="spec-pp" (click)="openModal($event, privacyPolicyModalTemplate)">Privacy</a>
<ng-template #termsOfServiceModalTemplate>
terms of service text goes here...
</ng-template>
<ng-template #privacyPolicyModalTemplate>
privacy policy text goes here...
</ng-template>
export class FooterComponent BsModalRef;
constructor(private modalService: BsModalService)
openModal($event: Event, template: TemplateRef<NgTemplateOutlet>): void
$event.preventDefault();
this.modalRef = this.modalService.show(template,
class: 'modal-dialog-scrollable'
);
How can I test that the links open the correct template? I need to be able to select the templateRef ID from my test, but I'm not sure how to do this. here's my test
it('should call the openModal() method when clicking on the privacy policy link', () =>
spyOn(component, 'openModal');
const link = debugEl.query(By.css('#spec-pp'));
//This next line is wrong and does not work
const tmpl = debugEl.query(By.directive(TemplateRef));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledWith(new MouseEvent('click'), tmpl);
);
I know that debugEl.query(By.directive(TemplateRef))
does not work... but that's just to give an idea of what I want to do here. How do I select a specific template from the component I'm testing?
Edit: The answer from @neo below is the solution, but I was able to take his solution and package it up into a re-usable helper function
/**
* Used for detecting an `<ng-template>` element reference that was passed to a function, typically for modals
* We don't have access to much except the name of the template and a number that it maps to internally.
* If we can return the number, then we've found the template by name, which is all we really want to do here
* //https://stackoverflow.com/a/55432163/79677
*/
export const templateExists = (template: TemplateRef<NgTemplateOutlet>, templateName: string): boolean =>
// tslint:disable-next-line:no-any -- There is no other way to get this object, it doesn't exist in the typedefs!
const refs = (template as any)._def.references as [templateName: string]: number;
//If we have a number, then we've found the template by name
return !isNaN(refs[templateName]);
;
Use it like this:
it('should call the openModal() method when clicking on the privacy policy link', () =>
const modalSpy = spyOn(component, 'openModal');
const link = debugEl.query(By.css('.footer-nav .spec-privacy'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(templateExists(modalSpy.calls.mostRecent().args[1], 'privacyPolicyModalTemplate')).toEqual(true);
);
angular angular-template angular-test angular-testing
I have the following component that has links to open a modal, which I can vary the content of by passing a template reference into.
<a id="spec-tos" (click)="openModal($event, termsOfServiceModalTemplate)">Terms of Service</a>
<a id="spec-pp" (click)="openModal($event, privacyPolicyModalTemplate)">Privacy</a>
<ng-template #termsOfServiceModalTemplate>
terms of service text goes here...
</ng-template>
<ng-template #privacyPolicyModalTemplate>
privacy policy text goes here...
</ng-template>
export class FooterComponent BsModalRef;
constructor(private modalService: BsModalService)
openModal($event: Event, template: TemplateRef<NgTemplateOutlet>): void
$event.preventDefault();
this.modalRef = this.modalService.show(template,
class: 'modal-dialog-scrollable'
);
How can I test that the links open the correct template? I need to be able to select the templateRef ID from my test, but I'm not sure how to do this. here's my test
it('should call the openModal() method when clicking on the privacy policy link', () =>
spyOn(component, 'openModal');
const link = debugEl.query(By.css('#spec-pp'));
//This next line is wrong and does not work
const tmpl = debugEl.query(By.directive(TemplateRef));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledWith(new MouseEvent('click'), tmpl);
);
I know that debugEl.query(By.directive(TemplateRef))
does not work... but that's just to give an idea of what I want to do here. How do I select a specific template from the component I'm testing?
Edit: The answer from @neo below is the solution, but I was able to take his solution and package it up into a re-usable helper function
/**
* Used for detecting an `<ng-template>` element reference that was passed to a function, typically for modals
* We don't have access to much except the name of the template and a number that it maps to internally.
* If we can return the number, then we've found the template by name, which is all we really want to do here
* //https://stackoverflow.com/a/55432163/79677
*/
export const templateExists = (template: TemplateRef<NgTemplateOutlet>, templateName: string): boolean =>
// tslint:disable-next-line:no-any -- There is no other way to get this object, it doesn't exist in the typedefs!
const refs = (template as any)._def.references as [templateName: string]: number;
//If we have a number, then we've found the template by name
return !isNaN(refs[templateName]);
;
Use it like this:
it('should call the openModal() method when clicking on the privacy policy link', () =>
const modalSpy = spyOn(component, 'openModal');
const link = debugEl.query(By.css('.footer-nav .spec-privacy'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(templateExists(modalSpy.calls.mostRecent().args[1], 'privacyPolicyModalTemplate')).toEqual(true);
);
angular angular-template angular-test angular-testing
angular angular-template angular-test angular-testing
edited Apr 11 at 16:24
CBarr
asked Mar 28 at 19:00
CBarrCBarr
13.9k17 gold badges71 silver badges106 bronze badges
13.9k17 gold badges71 silver badges106 bronze badges
Can you provide theBsModalRef
andBsModalService
classes, I think I may able to help you.
– Anuradha Mudalige
Mar 28 at 19:43
those are fromngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them
– CBarr
Mar 28 at 21:22
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14
add a comment
|
Can you provide theBsModalRef
andBsModalService
classes, I think I may able to help you.
– Anuradha Mudalige
Mar 28 at 19:43
those are fromngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them
– CBarr
Mar 28 at 21:22
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14
Can you provide the
BsModalRef
and BsModalService
classes, I think I may able to help you.– Anuradha Mudalige
Mar 28 at 19:43
Can you provide the
BsModalRef
and BsModalService
classes, I think I may able to help you.– Anuradha Mudalige
Mar 28 at 19:43
those are from
ngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them– CBarr
Mar 28 at 21:22
those are from
ngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them– CBarr
Mar 28 at 21:22
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14
add a comment
|
1 Answer
1
active
oldest
votes
Sorry for the delay, been busy these days. You should modify your spec.ts
as follows.
import TestBed, async, ComponentFixture from '@angular/core/testing';
import FooterComponent from './footer.component';
import BrowserModule, By from '@angular/platform-browser';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import MatButtonModule from '@angular/material';
import ModalModule from 'ngx-bootstrap';
describe('FooterComponent ', () =>
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() =>
TestBed.configureTestingModule(
declarations: [
FooterComponent
],
imports: [
// your imports here
ModalModule.forRoot()
]
).compileComponents();
));
beforeEach(() =>
fixture = TestBed.createComponent(FooterComponent);
component = fixture.debugElement.componentInstance;
fixture.detectChanges();
);
it('should create the app', () =>
expect(component).toBeTruthy();
);
it('should call the openModal() method when clicking on the links', () =>
const obj = spyOn(component, 'openModal');
let link = fixture.debugElement.query(By.css('#spec-tos'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(obj.calls.mostRecent().args[1]._def.references.termsOfServiceModalTemplate).toBeDefined();
link = fixture.debugElement.query(By.css('#spec-pp'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledTimes(2);
expect(obj.calls.mostRecent().args[1]._def.references.privacyPolicyModalTemplate).toBeDefined();
);
);
Enjoy!!
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
add a comment
|
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/4.0/"u003ecc by-sa 4.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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405056%2fselecting-a-specific-templateref-from-angular-component-test%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
Sorry for the delay, been busy these days. You should modify your spec.ts
as follows.
import TestBed, async, ComponentFixture from '@angular/core/testing';
import FooterComponent from './footer.component';
import BrowserModule, By from '@angular/platform-browser';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import MatButtonModule from '@angular/material';
import ModalModule from 'ngx-bootstrap';
describe('FooterComponent ', () =>
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() =>
TestBed.configureTestingModule(
declarations: [
FooterComponent
],
imports: [
// your imports here
ModalModule.forRoot()
]
).compileComponents();
));
beforeEach(() =>
fixture = TestBed.createComponent(FooterComponent);
component = fixture.debugElement.componentInstance;
fixture.detectChanges();
);
it('should create the app', () =>
expect(component).toBeTruthy();
);
it('should call the openModal() method when clicking on the links', () =>
const obj = spyOn(component, 'openModal');
let link = fixture.debugElement.query(By.css('#spec-tos'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(obj.calls.mostRecent().args[1]._def.references.termsOfServiceModalTemplate).toBeDefined();
link = fixture.debugElement.query(By.css('#spec-pp'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledTimes(2);
expect(obj.calls.mostRecent().args[1]._def.references.privacyPolicyModalTemplate).toBeDefined();
);
);
Enjoy!!
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
add a comment
|
Sorry for the delay, been busy these days. You should modify your spec.ts
as follows.
import TestBed, async, ComponentFixture from '@angular/core/testing';
import FooterComponent from './footer.component';
import BrowserModule, By from '@angular/platform-browser';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import MatButtonModule from '@angular/material';
import ModalModule from 'ngx-bootstrap';
describe('FooterComponent ', () =>
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() =>
TestBed.configureTestingModule(
declarations: [
FooterComponent
],
imports: [
// your imports here
ModalModule.forRoot()
]
).compileComponents();
));
beforeEach(() =>
fixture = TestBed.createComponent(FooterComponent);
component = fixture.debugElement.componentInstance;
fixture.detectChanges();
);
it('should create the app', () =>
expect(component).toBeTruthy();
);
it('should call the openModal() method when clicking on the links', () =>
const obj = spyOn(component, 'openModal');
let link = fixture.debugElement.query(By.css('#spec-tos'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(obj.calls.mostRecent().args[1]._def.references.termsOfServiceModalTemplate).toBeDefined();
link = fixture.debugElement.query(By.css('#spec-pp'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledTimes(2);
expect(obj.calls.mostRecent().args[1]._def.references.privacyPolicyModalTemplate).toBeDefined();
);
);
Enjoy!!
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
add a comment
|
Sorry for the delay, been busy these days. You should modify your spec.ts
as follows.
import TestBed, async, ComponentFixture from '@angular/core/testing';
import FooterComponent from './footer.component';
import BrowserModule, By from '@angular/platform-browser';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import MatButtonModule from '@angular/material';
import ModalModule from 'ngx-bootstrap';
describe('FooterComponent ', () =>
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() =>
TestBed.configureTestingModule(
declarations: [
FooterComponent
],
imports: [
// your imports here
ModalModule.forRoot()
]
).compileComponents();
));
beforeEach(() =>
fixture = TestBed.createComponent(FooterComponent);
component = fixture.debugElement.componentInstance;
fixture.detectChanges();
);
it('should create the app', () =>
expect(component).toBeTruthy();
);
it('should call the openModal() method when clicking on the links', () =>
const obj = spyOn(component, 'openModal');
let link = fixture.debugElement.query(By.css('#spec-tos'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(obj.calls.mostRecent().args[1]._def.references.termsOfServiceModalTemplate).toBeDefined();
link = fixture.debugElement.query(By.css('#spec-pp'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledTimes(2);
expect(obj.calls.mostRecent().args[1]._def.references.privacyPolicyModalTemplate).toBeDefined();
);
);
Enjoy!!
Sorry for the delay, been busy these days. You should modify your spec.ts
as follows.
import TestBed, async, ComponentFixture from '@angular/core/testing';
import FooterComponent from './footer.component';
import BrowserModule, By from '@angular/platform-browser';
import BrowserAnimationsModule from '@angular/platform-browser/animations';
import MatButtonModule from '@angular/material';
import ModalModule from 'ngx-bootstrap';
describe('FooterComponent ', () =>
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() =>
TestBed.configureTestingModule(
declarations: [
FooterComponent
],
imports: [
// your imports here
ModalModule.forRoot()
]
).compileComponents();
));
beforeEach(() =>
fixture = TestBed.createComponent(FooterComponent);
component = fixture.debugElement.componentInstance;
fixture.detectChanges();
);
it('should create the app', () =>
expect(component).toBeTruthy();
);
it('should call the openModal() method when clicking on the links', () =>
const obj = spyOn(component, 'openModal');
let link = fixture.debugElement.query(By.css('#spec-tos'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalled();
expect(obj.calls.mostRecent().args[1]._def.references.termsOfServiceModalTemplate).toBeDefined();
link = fixture.debugElement.query(By.css('#spec-pp'));
link.triggerEventHandler('click', null);
expect(component.openModal).toHaveBeenCalledTimes(2);
expect(obj.calls.mostRecent().args[1]._def.references.privacyPolicyModalTemplate).toBeDefined();
);
);
Enjoy!!
answered Mar 30 at 13:57
Anuradha MudaligeAnuradha Mudalige
4323 silver badges10 bronze badges
4323 silver badges10 bronze badges
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
add a comment
|
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
Very cool, thank you! Too bad these things aren't strongly typed, but at least I can make them testable
– CBarr
Apr 1 at 13:16
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405056%2fselecting-a-specific-templateref-from-angular-component-test%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Can you provide the
BsModalRef
andBsModalService
classes, I think I may able to help you.– Anuradha Mudalige
Mar 28 at 19:43
those are from
ngx-bootstrap
valor-software.com/ngx-bootstrap/#/modals - I don't own them– CBarr
Mar 28 at 21:22
I’ve added the answer below, can you check it?
– Anuradha Mudalige
Mar 31 at 4:14