Here's the Component I'm working with:
@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss']
})
export class SignUpComponent implements OnInit {
specialLink: string;
constructor(
private activatedRoute: ActivatedRoute,
) {
this.specialLink = this.activatedRoute.snapshot.params.id;
console.log('TEST1', this.specialLink);
}
Now, let's take a look at my test cases:
describe('SignUpComponent Testing', () => {
let component: SignUpComponent;
let fixture: ComponentFixture<SignUpComponent>;
let ActivatedRouteMock: any;
beforeEach(async(() => {
ActivatedRouteMock = {
snapshot: {
params: { id: '123' }
},
};
TestBed.configureTestingModule({
declarations: [ SignUpComponent ],
imports: [ RouterTestingModule ],
providers: [
{provide: ActivatedRoute, useValue: ActivatedRouteMock}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SignUpComponent);
component = fixture.componentInstance;
});
describe('Function calls', () => {
beforeEach(() => {
fixture.detectChanges();
});
describe('Testing for Special Link', () => {
it('should call setSpecialSignup() method when user is coming from specialLink', () => {
spyOn(ActivatedRouteMock, 'snapshot');
console.log('Test2', component.specialLink)
expect(ActivatedRouteMock.snapshot).toHaveBeenCalled();
});
I have verified that activatedRoute has been called correctly. The two 'console.log' statements confirm this by displaying the correct value (123). So why am I encountering this error message:
Expected spy snapshot to have been called
? What could be causing this discrepancy?