Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jackie1santana/47fa7ee6e17f6612300ad6450b531acc to your computer and use it in GitHub Desktop.
Save jackie1santana/47fa7ee6e17f6612300ad6450b531acc to your computer and use it in GitHub Desktop.
๐Ÿ”น Test Case 1: Cover goToTemplatePage with complete date
ts
Copy
Edit
it('should validate and format date when complete date is present', async () => {
component.isCompleteDate = () => true;
component.userProvidedDate = '01/01/2024';
component.formatUserProvidedDate = jest.fn();
await component.goToTemplatePage();
expect(component.formatUserProvidedDate).toHaveBeenCalledWith('01/01/2024');
});
๐Ÿ”น Test Case 2: this.data?.date missing โ€“ triggers error.date
ts
Copy
Edit
it('should set error.date when this.data?.date is missing', async () => {
component.data = null;
await component.goToTemplatePage();
expect(component.error.date).toBe(true);
});
๐Ÿ”น Test Case 3: Cover this.userSelectedState check
ts
Copy
Edit
it('should set error.state when userSelectedState is missing', async () => {
component.userSelectedState = '';
await component.goToTemplatePage();
expect(component.error.state).toBe(true);
});
๐Ÿ”น Test Case 4: Cover this.showZipCode and this.data.postalCode
ts
Copy
Edit
it('should set error.postalCode when showZipCode is true and postalCode is missing', async () => {
component.showZipCode = true;
component.data = { postalCode: '' };
await component.goToTemplatePage();
expect(component.error.postalCode).toBe(true);
});
๐Ÿ”น Test Case 5: Cover this.sharedStateService.setZipCode(...) execution
ts
Copy
Edit
it('should call sharedStateService.setZipCode if showZipCode is true', async () => {
component.showZipCode = true;
component.data = { postalCode: '12345' };
component.sharedStateService = { setZipCode: jest.fn() } as any;
await component.goToTemplatePage();
expect(component.sharedStateService.setZipCode).toHaveBeenCalledWith('12345');
});
๐Ÿ”น Test Case 6: Trigger trackAnalytics block (next button)
ts
Copy
Edit
it('should call trackAnalytics for eventName', () => {
component.eventName = 'TestEvent';
window.trackAnalytics = jest.fn();
component.goToTemplatePage();
expect(window.trackAnalytics).toHaveBeenCalled();
});
Let me know if you want these extracted into a full test file, or if you want me to break down Playwright vs Jest style if this is part of E2E. I can also auto-mock your sharedStateService, trackAnalytics, and any async behavior to pass SonarQube line coverage.
Want me to finish out the full spec file template for these?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment