Is there a way to test the functionality of the form
without considering Mixpanel? I am encountering an error as follows.
login.component.ts
ngOnInit() {
Mixpanel.trackEvent("View Screen", { "Screen Name": "Login" });
this.createForm();
}
createForm() {
this.form = this.fb.group({
email: ["", Validators.compose([Validators.required, Validators.pattern(RegexValidators.email)])],
password: ["", Validators.required]
});
}
login.component.spec.ts
import { CoreModule } from './../app.core.module';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginComponent } from './login.component';
import { APP_BASE_HREF } from '@angular/common';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule, CoreModule],
declarations: [],
providers: [
{
provide: APP_BASE_HREF,
useValue: '/'
}
]
});
//create component and test fixture
fixture = TestBed.createComponent(LoginComponent);
// get test component from the fixture
component = fixture.componentInstance;
component.ngOnInit();
}));
it('form invalid when empty', () => {
expect(component.form.valid).toBeFalsy();
});
});
Error:
ReferenceError: mixpanel is not defined
at Object.trackEvent (http://localhost:9876/_karma_webpack_/webpack:/src/mixpanel.functions.ts:5:5)
at LoginComponent../src/app/login/login.component.ts.LoginComponent.ngOnInit (http://localhost:9876/_karma_webpack_/webpack:/src/app/login/login.component.ts:25:14)
at Object.<anonymous> (http://localhost:9876/_karma_webpack_/webpack:/src/app/login/login.component.spec.ts:27:15)
...